how to make New lines in a cell using phpexcel
i have problem with php excel,
i want to make new line in one cell but i can't, i have tried using \n or <br /> but itsn't work. this my cod开发者_如何学运维e:
$objPHPExcel->getActiveSheet()->setCellValue('H5', 'Hello\nWorld'); // i need this show in two line
$objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
fyi: my format excel is xls not xlsx. many thanks :)
$objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\nWorld");
$objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
Works for me...
You should always use double quotes when you add escape sequences in a PHP string.
you should use 'r' to break into new line into excel with php
and use double quotes when you add escape sequences in a PHP string.
$objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\r World");
$objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
Improved answer based on Ravin and others
$objPHPExcel
->getActiveSheet()
->setCellValue('H5', "Hello".PHP_EOL." World");
$objPHPExcel
->getActiveSheet()
->getStyle('H5')
->getAlignment()
->setWrapText(true);
We can set for the default style, so don't need to specify for each cell range:
$objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);
To achieve next line but same cell forxcel export, this is the simplest solution.
<tr>
<td style="wrap-text: true">
Test
<br />
Test2
</td>
</tr>
精彩评论