ColdFusion11: CFContent doesn't write openable excel file

1.8k views Asked by At

I'm trying to do a simple task in ColdFusion: Generate an excel file and have it downloaded in the browser. I've got this:

<cfset local.sheet = SpreadsheetNew("My Spreadsheet", "true") />
<cfset SpreadsheetAddRow(local.sheet, "Col1,Col2,Col3") />

<cfheader name="content-disposition" value="attachment;filename=NiceName.xlsx" />
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(local.sheet)#" reset="true" />

Which did work perfectly on CF9, however it doesn't on CF11. When opening the file, it says:

Die Datei 'NiceName.xlsx' kann von Excel nicht geöffnet werden, da das Dateiformat oder die Dateierweiterung ungültig ist. Überprüfen Sie, ob die Datei beschädigt ist und ob die Dateierweiterung dem Dateiformat entspricht.

Which translates to something like:

Excel cannot open the file 'NiceName.xlsx', because either the file-format or -ending is invalid. Please verify, if the file is corrupted and wether the file-ending corresponds to the file-format.


I can:

  • <cfmailparam> the sheet and receive the file via mail.
  • <cfspreadsheet action="write"> the sheet and receive the file on the server.

In both cases, the files are readable.


I have tried:

  • <cfspreadsheet action="write"> the sheet, and then use <cfcontent file="#pathToFile#">, which doesn't work.
  • Checked my IIS for URL-Rewrite-Rules.
  • Checked my IIS for the .xlsx MIME-Type. It's the same as in my code.
  • Added a <cfabort> at the end, so nothing else would happen somehow.

But nothing helped.


I'm using:

  • ColdFusion 11 (11,0,0,289974) with Tomcat 7.0.52.0
  • Windows Server 2008 R2 Standard 64-bit
  • Microsoft Office 2013
  • IIS 7.5.7600.16385
1

There are 1 answers

3
Mark A Kruger On

Try using application/vnd.ms-excel instead of the openoffice variety. This is going to be an excel specific mime type. Folks using openoffice will convert automatically because they have it set up that way. That's the only thing I see here.