We have a web application written in PHP that exports MySQL query results to an Excel file using PEAR Spread开发者_StackOverflowsheet 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.
I think your comment about windows 95 tenticles still hanging about, may be correct.
Checking my registry, HKEY_CLASSES_ROOT/.xls has a default value of OpenOffice.org.Xls.
When I look up HKEY_CLASSES_ROOT/OpenOffice.org.Xls this has a default value of "Microsoft Excel 97-2003 Worksheet", which I think is the type you actually want.
Underneath this, at HKEY_CLASSES_ROOT/OpenOffice/org.XLS/shell/open/command is the actual command used - on my machine this is "C:\Program Files (x86)\OpenOffice.org 3\program\scalc.exe" -o "%1" but I have OpenOffice, not Excel. Yours will be different.
Check those entries, and see if the value make sense on your client's machine(s). You might find it easy to point .xls to the later version of Excel.
Make a careful note of what you change the registry FROM before you make any changes - so you can put it back if it dos not work.
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.
精彩评论