Premlatha
Premlatha

Reputation: 1976

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.

Upvotes: 6

Views: 19235

Answers (4)

Somio
Somio

Reputation: 1

here try this. it will make every used cell (cell with value in it) height to 15.

sheet = $spreadsheet->getActiveSheet();
foreach ($sheet->getRowIterator() as $row) {
            $sheet->getRowDimension($row->getRowIndex())->setRowHeight(15);
        }

Upvotes: 0

GALON MARKJAYPEE
GALON MARKJAYPEE

Reputation: 1

Here you go Brother.

    // Assuming you have 50 rows or 100 rows above to format
    $a = 50; 
    for($i = 0; $i<$a;$i++){
    $spreadsheet->getActiveSheet()->getRowDimension($i)->setRowHeight(14.25);   
    }
    you can use this as shown above my $a variable assigned 50 rows;

Upvotes: 0

Alejandro De Castro
Alejandro De Castro

Reputation: 2247

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.

Upvotes: 7

LF-DevJourney
LF-DevJourney

Reputation: 28529

Set the default row height with:

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

Upvotes: 4

Related Questions