How to suppress the file corrupt warning at Excel download?
This problem results from a feature called Extension Hardening, and you can find more information about it here
I've run into this problem a lot in my projects, and like Jon said, turning off Extension Hardening is something that will have to be done by each client side user.
Unfortunately, the link above also states that there are no expected changes to this code until at least Office 14.
If you don’t want to look for a solution, but just want to solve the problem, insert this key in your registry to suppress the notification:
[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security] “ExtensionHardening”=dword:00000000
You can accomplish the above by doing the following:
- Open your Registry (Start -> Run -> regedit.exe)
- Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
- Right click in the right window and choose New -> DWORD
- Type “ExtensionHardening” as the name (without the quotes)
- Verify that the data has the value “0″
For the old Excel format (.xls)
Assuming you create your spreadsheet object with this syntax:
<cfset sheet = SpreadsheetNew() />
You would use this to create the download:
<cfheader name="content-disposition" value="attachment;filename=my_spreadsheet.xls">
<cfcontent type="application/vnd.ms-excel" variable="#spreadsheetReadBinary(sheet)#" reset="true">
For the newer Excel format (.xlsx)
Create your spreadsheet object with this syntax:
<cfset sheet = SpreadsheetNew("", "true") />
And use this to create the download:
<cfheader name="content-disposition" value="attachment;filename=my_xml_spreadsheet.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(sheet)#" reset="true">
Thanks to Raymond Camden for the bulk of this (his example was for creating the spreadsheet in the older format -- I updated for the newer format and use slightly different MIME values).