从html到xml的生成.警告"文件格式与文件扩展名指定的格式不一致"


The generation from html to xls. Warning "The file format differs from the format that the file name extension specifies"

生成的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();

根据微软的支持页面:

警告消息是添加到的用户通知功能Excel 2007。警告消息可以帮助防止意外的问题这可能会发生,因为两者之间可能不相容文件的实际内容和文件扩展名。

所以,有了这个,你的问题在于你保存HTML内容的文件扩展名为。xls,因此,Excel总是抛出警报,因为文件内容与文件扩展名不同,无论你指定什么内容类型。

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