Autoheight does not work on merged cells. I think this is a problem with Excel, not with PHPExcel. If you want to do this, you must use work. It is mine...
I have a function that accepts text, splits into lines on the lines of a new line ('\ n'), and calculates the number of lines needed to “fit” the text, depending on the number of characters in the line (script coefficient).
function getRowcount($text, $width=55) { $rc = 0; $line = explode("\n", $text); foreach($line as $source) { $rc += intval((strlen($source) / $width) +1); } return $rc; }
For my report, the script factor obtained by trial and error is 55. Then I use the above function in my code ...
$purpose = $survey["purpose"]; $numrows = getRowcount($purpose); $objPHPExcel->getActiveSheet()->setCellValue('B'.$xlrow, 'Report Purpose'); $objPHPExcel->getActiveSheet()->getStyle('B'.$xlrow)->applyFromArray($fmt_cover_bold); $objPHPExcel->getActiveSheet()->setCellValue('C'.$xlrow, $purpose); $objPHPExcel->getActiveSheet()->getRowDimension($xlrow)->setRowHeight($numrows * 12.75 + 2.25); $objPHPExcel->getActiveSheet()->mergeCells('C'.$xlrow.':E'.$xlrow); $objPHPExcel->getActiveSheet()->getStyle('C'.$xlrow.':E'.$xlrow)->applyFromArray($fmt_normal_wrap); $xlrow++;
I add 2.25 to give a little separation between this cell and the next.
source share