49

I am using phpexcel to generate excel document with PHP.

the question is, how to make auto height row using phpexcel? many thanks :)

bungdito
  • 3,556
  • 4
  • 31
  • 38

4 Answers4

74
$excel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);

Should set the row height to 'auto' for row 1.

pkavanagh
  • 1,036
  • 9
  • 4
56
$excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);
Bora
  • 10,529
  • 5
  • 43
  • 73
Dhaval
  • 569
  • 4
  • 5
22

To change height of all rows to auto you can do:

foreach($xls->getActiveSheet()->getRowDimensions() as $rd) { 
    $rd->setRowHeight(-1); 
}
Kamil Szot
  • 17,436
  • 6
  • 62
  • 65
  • Maybe you can help me. Look at this : https://stackoverflow.com/questions/56469303/how-do-i-make-automatic-height-row-based-on-content-in-the-maatwebsite-version-3 – moses toh Jun 06 '19 at 02:48
5

You can set it by using following code,

$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
$objPHPExcel->getActiveSheet()->getStyle('E')->getAlignment()->setWrapText(true);
Vivek Parmar
  • 773
  • 1
  • 10
  • 26