PHP Generate / Export Microsoft Excel Files

I was looking for a good Excel file generation class and have not found it yet - the number one problem is that, although I can get the exported file to open in Excel (works in 2007), I always get a warning saying: "the file is in another format for the file extension. "

I noticed that Excel export to phpMyAdmin even generates the above warning message.

What code do other users use for this general requirement?

Quick update If I installed the file extension of my generated Excel file as xml, it will open in the browser (although I send the correct headers), but if I want to save the xml file and then open it from Excel, it works without any warnings! Unfortunately, this is more of a hassle for users than just clicking “Continue Anyway” with the warning I get. Any ideas?

+5
source share
5 answers

I found that adding the following in the xml signature in my generated Excel file ensures that Excel opens the file with the xml file extension (and not with a web browser):

 <?mso-application progid=\"Excel.Sheet\"?>

I also set 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"');
+2
+8

Spreadsheet_Excel_Writer PEAR

CSV.
Microsoft Excels csv: (;)

+2

, regedit

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security]
"ExtensionHardening"=dword:00000000
  • → → regedit
  • "HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY"
  • DWORD
  • "ExtensionHardening" 0
+2

,

? "foo.xlsx" "foo.xls".

0

All Articles