Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel, auto resize row height

Tags:

php

phpexcel

I would like to display the whole text on a generated .xls with PHPExcel 1.8.0. Currently, the cell (actually the whole row) isn't resized even though it didn't set any row height.

here are some screenshots :

What i got (generated)

What i would like (obtained on double clicking the "resize row height")

Here is my code :

$this->xls->getActiveSheet()->getRowDimension($this->row)->setRowHeight(-1);

$this->xls->getActiveSheet()->getStyle("A".$this->row.":F".$this->row)->getAlignment()->setWrapText(true);

$this->xls->getActiveSheet()->getCell("A".$this->row)->setValue(APPLICATION_ACADEMY);
$this->xls->getActiveSheet()->getCell("B".$this->row)->setValue(date("d/m/Y"));
$this->xls->getActiveSheet()->getCell("C".$this->row)->setValue($fait['nature'] === null ? $fait['codeNature'] : $fait['nature']);
$this->xls->getActiveSheet()->getCell("D".$this->row)->setValue($fait['etablissement']);

I used what i already found on stack (setTextWrap / setRowHeight(-1)) but it has no effect

Anyone got an idea ? Is it even possible ? thanks.

like image 945
GdC Avatar asked Oct 16 '15 08:10

GdC


1 Answers

Below is working for me but its for single row:

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

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

foreach($xls->getActiveSheet()->getRowDimensions() as $rd) { 
    $rd->setRowHeight(-1); 
}
like image 183
Dheeraj Nayak Avatar answered Oct 27 '22 00:10

Dheeraj Nayak