我正在尝试在 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 上却不行。打开文件时,它显示:
日期“NiceName.xlsx”可以在 Excel 中使用,因为日期格式或日期格式不正确。 Überprüfen Sie,ob die i beschädigt ist und ob dieerweiterung dem Dateiformat entspricht。
这可以翻译为:
Excel 无法打开文件“NiceName.xlsx”,因为文件格式或结尾无效。请验证文件是否损坏以及文件结尾是否与文件格式相对应。
<小时/>我可以:
-
<cfmailparam>
表格并通过邮件接收文件。 -
<cfspreadsheet action="write">
工作表并在服务器上接收文件。
在这两种情况下,文件都是可读的。
<小时/>我已经尝试过:
-
<cfspreadsheet action="write">
工作表,然后使用<cfcontent file="#pathToFile#">
,这不起作用。 - 检查了我的 IIS 的 URL 重写规则。
- 检查了我的 IIS 中的 .xlsx MIME 类型。这与我的代码中的相同。
- 添加了
<cfabort>
最后,所以不会发生任何其他事情。
但没有任何帮助。
<小时/>我正在使用:
- ColdFusion 11 (11,0,0,289974) 与 Tomcat 7.0.52.0
- Windows Server 2008 R2 标准版 64 位
- 微软 Office 2013
- IIS 7.5.7600.16385
最佳答案
尝试使用 application/vnd.ms-excel
而不是 openoffice 品种。这将是 Excel 特定的 mime 类型。使用 openoffice 的人会自动转换,因为他们已经这样设置了。这是我在这里看到的唯一东西。
关于excel - 冷融合11 : CFContent doesn't write openable excel file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277617/