mercredi 25 mars 2015

Error while opening generated excel file - 'filename.xls', is in a different format than specified by the file extension

I am generating a excel file using sql query and this code -



header("Content-type: application/octet-stream");

header("Content-Disposition: attachment; filename=excelfile.xls");


But when user generates the excel and downloads it and tries to open the file, they are getting this error -



"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?"


and on clicking on Yes the file is opening without any problem.


How can I get rid of the problem without bothering the user ?


I have read other threads in this forum but they are unclear or do not seem to work.


Like changing extension to xlsx does not work


Can anyone help ?


You can download sample of excel generated file from here


Aucun commentaire:

Enregistrer un commentaire