How to set the word wrap property to particular column using PhpExcel in Yii?
14,553
Wordwrap is set for individual cells, or for a range of cells, not for a specific column
$objPHPExcel->getActiveSheet()
->getStyle('B1:B100')
->getAlignment()
->setWrapText(true);
You may also want to set vertical alignment for those cells as well
$objPHPExcel->getActiveSheet()
->getStyle('B1:B100')
->getAlignment()
->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
Author by
Talk2Nit
Updated on June 04, 2022Comments
-
Talk2Nit over 1 year
I want to set the wordwrap property to a particular column. I have set the fixed width for that column. But when text is large it goes into the next cell. I want to wrap that text in same column.
I am using the phpExcel extension to export the data.
Here is the code.
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $row, "Sr No"); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $row, "Query"); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $row, "Additional Detail."); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(60); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(60);
Want to set wordwrap property to column B in my above code. Any help would be appreciated!
-
Talk2Nit almost 9 yearsI think we can set the Wordwrap to individual column. I did this way
$objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setWrapText(true);
But when I set this it's style gets removed. -
Mark Baker almost 9 years@Nitin - you can try doing that, but it won't work, PHPExcel does not support row or column styles
-
Talk2Nit almost 9 yearsI already set the style for whole sheet. But when I set wordwrap property to column as above it doesn't display the style for that column. Do you have any idea?