PHP Excel - 您尝试打开的文件.xls的格式与文件扩展名指定的格式不同


PHP Excel - The file you are trying to open .xls is in a different format than specified by the file extension

早上好,

我正在使用API JASPER"JasperClient.php",其中我使用函数runReport返回xls,并在php代码中我想从服务器下载Excel文件。

设置标头:

header('Content-type: application/vnd.ms-excel');header('Content-Disposition: attachment; filename=myfile.xls');

当我下载文件并尝试打开说:

您尝试打开的文件"文件名.xls"的格式与文件扩展名指定的格式不同。在打开文件之前,请验证文件是否未损坏且来自受信任的来源。是否要立即打开文件?

你能帮我吗?谢谢。

您正在创建 Excel 2007 文件吗?如果是这样,请尝试使用mimetype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet和文件扩展名.xslx