【问题标题】:The generation from html to xls. Warning "The file format differs from the format that the file name extension specifies"从html到xls的生成。警告“文件格式与文件扩展名指定的格式不同”
【发布时间】:2015-05-27 12:43:12
【问题描述】:

生成的 xls 文件打开(在 MS Excel 2013 中)并带有警告

文件格式与文件扩展名的格式不同 指定

,如果按“是”- 文件完全打开,但我希望没有此警告。 代码片段:

header("Content-Type: application/vnd.ms-excel; charset=windows-1251");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Disposition: attachment; filename=filename.xls);

echo<<<HTML
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251" />
</head>
<body>
<table border="1" cellspacing="0" cellpadding="0">
/* many lines */
</table>
</body>
</html>
HTML
die();

【问题讨论】:

标签: php excel warnings xls


【解决方案1】:

根据微软的支持页面:

警告消息是添加到的用户通知功能 Excel 2007。警告消息有助于防止出现意外问题 这可能是由于之间可能不兼容而发生的 文件的实际内容和文件扩展名。

因此,有了这个,您的问题在于您将带有文件扩展名的 HTML 内容保存为 .xls,因此,Excel 将始终抛出该警报,因为文件内容与文件扩展名不同,无论内容是什么您指定的类型。

https://support.microsoft.com/en-us/kb/948615

【讨论】:

    猜你喜欢
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多