Here is the issue I have a simple PHP file that exports a table to an excel file with the extension ".xls". The code that makes the export goes like this:
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=filename.xls" );
header("Content-Description: PHP/INTERBASE Generated Data" );
header("Expires: 0");
Rest of the PHP code that has HTML tags for the table
This PHP class is called from a buton that goes like this:
<input type="submit" name="button2" onclick = "this.form.action = 'ExcelExportFile.php'" value='Export to Excel'>
The browser prompts for the file to either be downloaded or saved. The issue starts when trying to open the downloaded file depending on which Excel version is installed in the user's computer:
- Excel 2010, Excel 2013: All it does is open Excel without opening the file, the program does not give any prompt or any warning, it just hangs on a grey window.
- Excel 2016 opens up the file not before saying the user that the file might be corrupted and asks the user if it's sure to open the file. Click Yes and the file opens correctly showing the table
I have tried the troubleshoot from Microsoft's web page but nothing works. The interesting part about here is that if you go File -> Open -> Recent Books and click on the downloaded file, now it opens up correctly without making any changes on the file whatsoever.