Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set auto height in PHPExcel not working

I am generating Excel using PHPExcel.

All Code Works Fine.But Auto height code is not Working.

I have tried following code.

Apply row height on specific row

$objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(-1); 

Apply row height on for all row

$objPHPExcel->getActiveSheet()->getDefaultRowDimension(1)->setRowHeight(-1);

I have also tried word wrap property with it.

$objPHPExcel->getActiveSheet()
    ->getStyle('B7')
    ->getAlignment()
    ->setWrapText(true);

But it give me result as below:

enter image description here

Note : Working in MS office,Not Working in Apache open Office and LibreOffice

like image 878
Yasin Patel Avatar asked Sep 05 '16 09:09

Yasin Patel


1 Answers

Have just added the following to the 01simple.php example

$value = "To be or not to be-that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and, by opposing, end them."; 
$objPHPExcel->getActiveSheet()->setCellValue('A12', $value); 
$objPHPExcel->getActiveSheet()->getRowDimension(12)->setRowHeight(-1); 
$objPHPExcel->getActiveSheet()->getStyle('A12')->getAlignment()->setWrapText(true);

and this creates correctly wrapped output for both Excel2007 and Excel5 Writers

like image 161
Mark Baker Avatar answered Nov 02 '22 00:11

Mark Baker