i have problem with php excel,
我有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 code:
我想在一个单元格中创建新行,但我不能,我尝试使用\ n或
但它不起作用。我的代码:
$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 :)
fyi:我的格式excel是xls而不是xlsx。非常感谢 :)
4 个解决方案
#1
85
$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.
在PHP字符串中添加转义序列时,应始终使用双引号。
#2
20
you should use 'r' to break into new line into excel with php
你应该使用'r'进入excel的新行使用php
and use double quotes when you add escape sequences in a PHP string.
在PHP字符串中添加转义序列时使用双引号。
$objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\r World");
$objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
#3
8
Improved answer based on Ravin and others
改进了基于Ravin和其他人的答案
$objPHPExcel
->getActiveSheet()
->setCellValue('H5', "Hello".PHP_EOL." World");
$objPHPExcel
->getActiveSheet()
->getStyle('H5')
->getAlignment()
->setWrapText(true);
#4
-1
To achieve next line but same cell forxcel export, this is the simplest solution.
要实现下一行但相同的单元格forxcel导出,这是最简单的解决方案。
<tr>
<td style="wrap-text: true">
Test
<br />
Test2
</td>
</tr>
#1
85
$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.
在PHP字符串中添加转义序列时,应始终使用双引号。
#2
20
you should use 'r' to break into new line into excel with php
你应该使用'r'进入excel的新行使用php
and use double quotes when you add escape sequences in a PHP string.
在PHP字符串中添加转义序列时使用双引号。
$objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\r World");
$objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
#3
8
Improved answer based on Ravin and others
改进了基于Ravin和其他人的答案
$objPHPExcel
->getActiveSheet()
->setCellValue('H5', "Hello".PHP_EOL." World");
$objPHPExcel
->getActiveSheet()
->getStyle('H5')
->getAlignment()
->setWrapText(true);
#4
-1
To achieve next line but same cell forxcel export, this is the simplest solution.
要实现下一行但相同的单元格forxcel导出,这是最简单的解决方案。
<tr>
<td style="wrap-text: true">
Test
<br />
Test2
</td>
</tr>