Auto height not working for me.

Topics: Developer Forum
Jan 11, 2013 at 5:30 PM
Edited Jan 11, 2013 at 5:33 PM

I am building a spreadsheet with a column that will hold a lot of text. I have set that column to wrap like this


$arrStyleContentsFormat = array(
    'font' => array(
	'bold' => false,
	'size' => 9
    'alignment' => array(
        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
	'wrap' => true,


Then as I loop through and build each row I am specifying a -1 in the rowheight like this


However when the spreadsheet prints the rows are small and I cannot see all the text. 

I am also tried using AutoSize, but that only extends the width, not the height.

I am using PHPExcel 1.7.7 on Windows 7 x64.



Aug 13, 2014 at 11:34 AM
Edited Aug 13, 2014 at 4:29 PM
There's also a problem setting autoHeight in phpExcel examples: 01simple.php

Here's the code:
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setCellValue('A8', "Hello\nWorld");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
If I open this xlsx file in Microsoft Excel Viewer everything works fine.
The problem starts when I'm trying to open it with LibreOffice Calc. It shows only one line of the "Hello World" text.

If I open this file in LibreOffice set autoHeight and resave it then it works good:

So the problem is with phpExcel which doesn't put all the info into the file.
I don't know how to fix this, so I've created a full review of this bug (with example files):

EDIT1 Difference in sharedStrings.xml

<sst xmlns="" uniqueCount="1"><si><t>Hello
<sst count="1" uniqueCount="1" xmlns=""><si><t>Hello&#10;World</t></si></sst>

EDIT2 Difference in sheet1.xml

<sheetData><row r="1" spans="1:1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData>
<sheetData><row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="28.35" outlineLevel="0" r="1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData>
Aug 13, 2014 at 5:02 PM
Edited Aug 13, 2014 at 5:25 PM
Solved by editing file "phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007\Worksheet.php" (lines 1001:1004):
All I did was adding else block like this...
private function _writeSheetData(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pStringTable = null)
                    // Row dimensions
                    if ($rowDimension->getRowHeight() >= 0) {
                        $objWriter->writeAttribute('customHeight', '1');
                        $objWriter->writeAttribute('ht', PHPExcel_Shared_String::FormatNumber($rowDimension->getRowHeight()));
                    } else {
                        $objWriter->writeAttribute('customHeight', 'false');
                        $objWriter->writeAttribute('ht', '0');
I've noticed that many params have no else block, but in here only 'ht' attribute was needed. It now works with LibreOffice! :-)
Oct 29, 2014 at 3:32 PM
I have the same problem and this solution does not help me... Does anybody have other suggestions?