嗨,我有以下代码:
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>";
Run Code Online (Sandbox Code Playgroud)
我试过了:
<td>Line 1\r\nLine 2</td>
<td>Line 1".chr(10) . chr(13)."Line 2</td>
Run Code Online (Sandbox Code Playgroud)
但似乎没有任何效果,我需要在单元格中进行换行,欢迎提出任何建议.我正在使用excel 2010.
我已经看过这个问题:Excel 2003数据中的换行符并没有用.
它没有显示错误,当我应用<br>它时会创建一个新行,当我使用时\r\n, \n, or chr(10) . chr(13),它会创建一个空格.
谢谢!!
经过大量搜索后发现这个网站:http: //www.bennadel.com/blog/1095-maintaining-line-breaks-in-an-html-excel-file.htm
这个标签解决了这个问题 <br style="mso-data-placement:same-cell;" />
谢谢你们的评论!!