Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 565
tehlivi Avatar asked Jul 02 '12 19:07

tehlivi


People also ask

How do you wrap text in PHPExcel?

I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true);

How do I add a new line in a cell in Excel using PHP?

Write a newline character "\n" in a cell (ALT+"Enter") In Microsoft Office Excel you get a line break in a cell by hitting ALT+"Enter".


1 Answers

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);  
like image 91
Mark Baker Avatar answered Sep 24 '22 18:09

Mark Baker