'set row height for all rows using phpspreadsheet

Default row height in excel is -1 which show 15 in excel.This row height automatically resize to 15.75 after add content.So, I set new default row height,15 for all rows. Still, row height getting auto resize. Then, I try to set row height for all rows from $sheet->getRowDimensions(). There is no content in $sheet->getRowDimensions(). So, $rd->setRowHeight(15) does not take effect.

$default_rowdimensions  =$sheet->getDefaultRowDimension();
$set_newdefaultrowheight=$sheet->getDefaultRowDimension()->setRowHeight(15); 
$rowdimension = $sheet->getRowDimensions();
echo '<pre>;
var_dump($rowdimension);
echo '</pre>';
foreach($rowdimension  as $rd) 
{ 
    $rd->setRowHeight(15); 
}

Is there any other ways to set row height for all rows before write to excel.

Thanks in advance.



Solution 1:[1]

Set the default row height with:

$sheet->getDefaultRowDimension()->setRowHeight(15);

Solution 2:[2]

For PhpSpreadSheet, the correct way to archive this is :

$spreadsheet->getActiveSheet()->getRowDimension('2')->setRowHeight(26);

Where 2 is the number of row and 26 is the height.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LF00
Solution 2 Ale DC