I've been looking for a good Excel file generation class and have yet to find one - my number one issue is that I although I can get the exported file to open in Excel (running 2007), I always get a warning saying "the file is in a different format to the file extension".
I noticed that the Excel export in phpMyAdmin even generates the aforementioned warning message.
What code do other users use for this common requirement?
Quick update If I set the file extension of my generated Excel file as xml it opens in the browser (even though I'm sending the correct headers), but if I choose to save the xml file and then open it from Excel, it works without any warnings! Unfortunately, that's more hassle for the users than simply clicking 'Proceed anyway' with the warning I'm getting. Any more ideas?
Use Spreadsheet_Excel_Writer from PEAR
or
Write the file to CSV format.
But use Microsoft Excels understanding of csv: A semicolon(;) as seperator
You also disable the dialogbox, using regedit
[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security]
“ExtensionHardening”=dword:00000000
- Start -> Run -> regedit
- Go to "HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY"
- New DWORD
- Type “ExtensionHardening” as the name and 0 as the value
I've discovered that adding the following, under the xml declaration in my generated Excel file, ensures Excel opens the file with an xml file extension (rather than the web browser):
<?mso-application progid=\"Excel.Sheet\"?>
I'm also setting the following headers in php:
// deliver header (as recommended in php manual)
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $filename . '.xml"');
the file is in a different format that
the file extension
Have you tried saving the file with another file extension? Like "foo.xlsx" instead of "foo.xls".