The only way described in this answer to your previous question on this question is: setting the line height for auto-tuning and aligning the cell for wrapping. This should work the same way, whether you use Excel5 Writer or Excel2007 Writer.
$objPHPExcel = new PHPExcel(); // Set some long string values in some cells $objPHPExcel->getActiveSheet()->getCell('A1')->setValue("This is a large block of text,\ncomprising several lines,\nthat will be set to autofit."); $objPHPExcel->getActiveSheet()->getCell('A2')->setValue("This is a large block of text that will NOT be set to autofit."); $objPHPExcel->getActiveSheet()->getCell('B1')->setValue("This is another large block of text without any line breaks, that will be set to autofit."); $objPHPExcel->getActiveSheet()->getCell('A3')->setValue("This is another large block of text,\ncomprising several lines,\nthat will be set to autofit."); $objPHPExcel->getActiveSheet()->getCell('A4')->setValue("This is another large block of text without any line breaks, that will be set to autofit but not wrap."); // Fix the column width to a reasonable size $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30); // Set text wrap for cells A1 and B1. This forces the text to wrap, but doesn't adjust the height of the row $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setWrapText(true); // Set rows 1, 3 and 4 to autofit the height to the size of text $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1); $objPHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(-1); $objPHPExcel->getActiveSheet()->getRowDimension(4)->setRowHeight(-1); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('testAutoHeight.xls');
EDIT
Added comments on the sample code to explain that each method being called actually does
Mark baker
source share