gutsout
gutsout

Reputation: 15

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

Generated xls file opens(in MS Excel 2013) with warning

The file format differs from the format that the file name extension specifies

, if press "Yes" - file perfectly opens, but I would like without this warning. The code fragment:

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();

Upvotes: 1

Views: 2171

Answers (1)

taxicala
taxicala

Reputation: 21759

As per Microsoft's support page:

The warning message is a user-notification function that was added to Excel 2007. The warning message can help prevent unexpected problems that might occur because of possible incompatibility between the actual content of the file and the file name extension.

So, having this on hand, your problem relies at that you are saving HTML contet with a file extension as .xls, thus, Excel will always throw that alert because the file content differs from the file extention, no matter what content type you specify.

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

Upvotes: 2

Related Questions