【发布时间】:2013-01-28 17:06:10
【问题描述】:
所以我有这个代码:
$output = '
<table class="sticky-enabled">
<thead><tr><th>Text0</th><th>Text1</th><th>Text2</th> </tr></thead>
<tbody id="">
<tr class="odd"><td>7</td><td>texttt</td><td>texttt</td> </tr>
</table>';
header("Content-type: application/vnd.ms-excel;");
header("Cache-Control: no-store, no-cache");
header("Content-Disposition: attachment; filename=file.xls");
print chr(255) . chr(254) . mb_convert_encoding($output, 'UTF-16LE', 'UTF-8');
exit;
这个东西会下载一个带有表格的 Excel 文件。
不过有两个问题:
- 当我使用 Excel 打开它时,它会显示您尝试打开的文件格式与扩展错误不同
- 当我尝试保存它时,默认文件扩展名是 .htm 而不是 xls
有没有办法操纵标题等以解决这两个问题?
【问题讨论】:
-
最简单的答案是使用 PHPExcel 或可以执行此操作的许多其他 PHP 库之一创建真正的 BIFF Excel 文件;那么你也不必用笨拙的编码更改来搞砸你的输出
标签: php html excel header html-table