HTML 表到 *.xls 的编码问题
我的导出脚本:
if($_POST){
$file = 'FKDB_XLS';
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel; charset=utf-8"); // dunno if the charset does anything for this application type..
header("Content-Disposition: attachment; filename=$filename");
echo stripslashes($_SESSION['item']); unset($_SESSION['item']);
exit;
}
基本上,它只是将 HTML ($_SESSION['item']
as {rows}
问题是,当在 Excel 中打开时,一切正常,除了...所有值都写错了,所有 Ä、ņÅ
等等而不是 'Ā' 等。 。
我应该做什么来防止这种情况发生?
提前致谢!
My export script:
if($_POST){
$file = 'FKDB_XLS';
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel; charset=utf-8"); // dunno if the charset does anything for this application type..
header("Content-Disposition: attachment; filename=$filename");
echo stripslashes($_SESSION['item']); unset($_SESSION['item']);
exit;
}
Basicly, it just turns HTML ($_SESSION['item']
as <table>{rows}</table>
) into *.xls and allows Excel to draw tables from that data, as most of you know, probably.
The problem is, when opened in Excel, everything's OK, except... all the values are written incorrectly, with all the Ä, ņÅ
and so on instead of 'Ā' or so, again.
What should I do to prevent that?
Thanks in advance!
如果您正在编写要导入 Excel 的 HTML 标记,那么您需要确保在 HTML 标头中设置适当的元标记。在内容类型中指定字符集绝对没有任何效果。如果您只是编写一个表格,请将其包装在 HTML/HEAD/BODY 等中,以便您可以设置 HEAD 元标记。
我仍然不明白为什么人们要编写 HTML 并给文件添加 xls 扩展名,而创建真正的 Excel 文件是如此容易!
If you're writing HTML markup for import into excel, then you need to ensure that you're setting the appropriate meta tags in the HTML header. specifying charset in the Content type will have absolutely no effect at all. If you're simply writing a table, then wrap it in HTML/HEAD/BODY, etc so that you can set the HEAD meta tags.
I still don't understand why people write HTML and give the file an xls extension when it's so easy to create a real Excel file!