我正在尝试在 ColdFusion 中执行一项简单的任务:生成一个 excel 文件并将其下载到浏览器中。我有这个:
<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" />
在 CF9 上确实可以完美运行,但在 CF11 上却不行。打开文件时,它说:
Die Datei 'NiceName.xlsx' kann von Excel nicht geöffnet werden, das Dateiformat oder die Dateierweiterung ungültig ist。Überprüfen Sie, ob die Datei beschädigt ist und ob die Dateierweiterung dem Dateiformat entspricht。
这意味着:
Excel 无法打开文件“NiceName.xlsx”,因为文件格式或结尾无效。请验证文件是否已损坏以及文件结尾是否与文件格式相对应。
我可以:
<cfmailparam>
表并通过邮件接收文件。<cfspreadsheet action="write">
工作表并在服务器上接收文件。
在这两种情况下,文件都是可读的。
我努力了:
<cfspreadsheet action="write">
工作表,然后使用<cfcontent file="#pathToFile#">
,这是行不通的。- 检查我的 IIS 的 URL-Rewrite-Rules。
- 检查我的 IIS 的 .xlsx MIME 类型。这与我的代码中的相同。
- 最后添加了 a
<cfabort>
,所以不会发生其他任何事情。
但没有任何帮助。
我在用着:
- ColdFusion 11 (11,0,0,289974) 与 Tomcat 7.0.52.0
- Windows Server 2008 R2 标准版 64 位
- 微软办公软件 2013
- IIS 7.5.7600.16385