Search code examples
phpphpexcelexport-to-excel

The file format and the extension of filename.xls don't match. This file could be corrupted and unsafe


I had made a PHP script to output an excel(.xls) document from data extracted from MySQL database.

Exporting function is working fine.

The problem is when i open it on MS Excel it shows me following message before opening the file.

The file format and the extension of filename.xls don't match. This file could be corrupted and unsafe...

can you help me to resolve this warning message issue?

excel warning message:

excel warning message

array to be exported to excel:

array to be exported to excel

exported file:

exported file


Solution

  • you may change the extension to .xlsx, as MS Office 2013 or newer versions expects that as standard. Also try to use exact mime type when exported from php. you may search for mime types and test which meets your office installation.