Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP在excel的单元格中执行换行操作?_Php_Excel - Fatal编程技术网

如何使用PHP在excel的单元格中执行换行操作?

如何使用PHP在excel的单元格中执行换行操作?,php,excel,Php,Excel,嗨,我有以下代码: header('Content-type: application/vnd.ms-excel'); header("Content-Disposition: attachment; filename=archivo.xls"); header("Pragma: no-cache"); header("Expires: 0"); echo " <html> <head> <meta charset="utf-8"> <meta htt

嗨,我有以下代码:

header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=archivo.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo "
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="expires" content="0">
</head>
<body>
<table width="100%" border="1" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <td>Line 1<br>Line 2</td>
  </tr> 
</table>
</body>
</html>";
标题('Content-type:application/vnd.ms-excel');
标题(“内容处置:附件;文件名=archivo.xls”);
标题(“杂注:无缓存”);
标题(“到期日:0”);
回声“
第1行
第2行 ";
我试过:

<td>Line 1\r\nLine 2</td>
<td>Line 1".chr(10) . chr(13)."Line 2</td>
第1行\r\n第2行
第1行“.chr(10).chr(13)。”第2行
但似乎什么都不管用,我需要在牢房里换行,欢迎任何建议。我正在使用excel 2010

我已经考虑过这个问题了:但它不起作用

当我应用

时,它不会显示错误。当我使用
\r\n\n或chr(10)时,它会创建一个新行。chr(13)
,它创建了一个空间


谢谢

试一试PHP_EOL,它应该能让您了解正在使用的操作系统的新行特征

例如:

$output = 'Line 1' . PHP_EOL .
          'Line 2' . PHP_EOL .
          'Line 3';
您说charset=“utf-8”,但chr返回ASCII

这个怎么样;oP

utf8_encode(chr(10).chr(13))

在搜索此网站的大量内容后:

这个标签解决了这个问题


谢谢你的评论

应该添加双引号以包括换行符

'<td>Line 1' . "\r\n" . 'Line 2</td>'
“第1行”。“\r\n”。”第2行'

尝试
\n
而不是
\r\n
。Windows仅使用
\n
作为新行函数。请尝试使用“by\”或使用echo。这就是为什么开发人员试图假装HTML标记是Excel文件,然后又担心它无法通过括号上的EOF更正补丁(我编辑了您的代码)而感到沮丧的原因?那没用-7位字符的UTF-8编码是不可操作的,CR和LF都是7位字符。好吧,这很有趣。。尝试使用此中断标记:

我正在尝试将wp列表表导出到.csv。我的生命不能让牢房里的线断裂。我找到了你的答案,并尝试导出到.xls:它的工作就像一个符咒!谢谢你的帮助。