ColdFusion export to Excel using CFCONTENT doesn't work anymore
Mia Lopez
I've been using all my life <cfheader> and <cfcontent> tags in ColdFusion in order to export a HTML table in Excel format (.xls). So far, it worked just perfect, all exported files were good and opened without problems in Excel or OpenOfifce Calc.
Today I discovered that this doesn't work anymore: even if the code was not changed for years, the export result (file.xls) is no longer recognized as a valid Excel file. When I try to open the file using MS Excel I am getting this error message:
Can't open file. This file is unsupported by this version of Office.
OpenOffice Calc doesn't even start.
My code for exporting the Excel file from ColdFusion is as simple as this:
<cfheader name="Content-Disposition" value="attachment; filename=test.xls">
<cfcontent type="application/vnd.ms-excel">#Trim(VARIABLES.html_content)#If I open the exported file, it contains the HTML code of a simple table. Does anyone else experienced this problem recently?
31 Answer
Use This :
<cfheader name="Content-Disposition" value="inline; filename=test.xls">
<cfcontent type="application/msexcel">
#Trim(VARIABLES.html_content)#