tehlivi
tehlivi

Reputation: 810

PHPExcel and Text Wrapping

I know that this line of code will make the cell text-wrap:

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

'D1' being the chosen cell.

Instead of using this code for every cell I need wrapped, is there a way to make the entire Excel Worksheet automatically wrap everything?

Or is there a better practice technique to use for specified columns?

Upvotes: 67

Views: 124508

Answers (3)

james
james

Reputation: 351

$objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);

Upvotes: 35

Naitik Shah
Naitik Shah

Reputation: 513

Apply to column

$highestRow = $$objPHPExcel->getActiveSheet()->getHighestRow();
for ($row = 1; $row <= $highestRow; $row++){
    $sheet->getStyle("D$row")->getAlignment()->setWrapText(true);
}

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212402

Apply to a range:

$objPHPExcel->getActiveSheet()->getStyle('D1:E999')
    ->getAlignment()->setWrapText(true); 

Apply to a column

$objPHPExcel->getActiveSheet()->getStyle('D1:D'.$objPHPExcel->getActiveSheet()->getHighestRow())
    ->getAlignment()->setWrapText(true); 

Upvotes: 135

Related Questions