Search code examples
phpcontent-typeexport-to-excel

Browser opening downloaded Excel file in wrong version of Excel


We have a web application written in PHP that exports MySQL query results to an Excel file using PEAR Spreadsheet Excel Writer. I'm initiating the download via the following headers:

header( "Content-Type: application/vnd.ms-excel" );
header( "Content-Transfer-Encoding: binary" );
header( "Cache-Control: must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Disposition: attachment; filename=myfile.xls" );

As far as I can tell all of this works correctly. All users have Excel 97 and 2000. Problem is when the browser (exclusively IE7/8) prompts to save, "Save as type" defaults to Excel 95, and there are apparently some compatibility issues if the file is saved in that format. These are not technical users so asking them to change the filetype is hit or miss.

I told my client I can't control what the OS/browser does with the file when downloaded, but I'm hoping for confirmation of that. I also wonder if there's a possibility Excel 95 was upgraded and left some of its tentacles, so Windows still thinks it's a viable option.

Any thoughts or input appreciated.


Solution

  • It's a client side issue, there's nothing you can do about it. Your headers are correct. They will have to update their default application for opening XLS files.