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

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

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.

Setting the header:

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?

Can you help me please?
Thank you .

How to&Answers:

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