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

时间:2022-10-24 09:15:43

Good Morning,

早上好,

I am use a API JASPER "JasperClient.php" where i use the function runReport to return a xls and in php code i want to download Excel File from the server.

我使用API​​ JASPER“JasperClient.php”,其中我使用函数runReport返回xls和PHP代码我想从服务器下载Excel文件。

Setting the header:

设置标题:

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

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

When i'm download the file and try to open the says:

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

The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

您尝试打开的文件'filename.xls'的格式与文件扩展名指定的格式不同。在打开文件之前,请验证文件是否已损坏且来自受信任的源。你想现在打开文件吗?

Can you help me please? Thank you .

你能帮我吗?谢谢 。

1 个解决方案

#1


2  

Are you creating Excel 2007 files? If so try using mimetype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet and file extension .xslx

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

#1


2  

Are you creating Excel 2007 files? If so try using mimetype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet and file extension .xslx

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