是否可以在coldfusion中下载文件变量?

时间:2011-11-23 13:16:39

标签: coldfusion

使用Coldfusion的SpreadSheet()对象我创建了一个excel文件,现在用户需要能够下载它。

mySS = SpreadsheetNew();
format1 = StructNew();
format1.color="dark_green";
format1.size="24"; 
SpreadSheetSetCellValue(mySS, 7,2,3);
SpreadSheetFormatCell(mySS, format1, 2, 3);

基本上我想要像

这样的东西
<cfdownload var="#mySS#">
然而,它几乎从未如此简单。我意识到我可以编写该文件,然后使用cfheader \ cfcontent但是我尽量避免编写文件。

修改

基于我从speshak得到的建议,我尝试了

<cfcontent variable="#mySS#"  type="application/msexcel">

我得到的错误是,我错过了什么?

  

coldfusion.excel.ExcelInfo不是受支持的变量类型。该   变量应该包含二进制数据。

2 个答案:

答案 0 :(得分:3)

好的,所以感谢Raymond Camden's Post和speshak这里是最终的解决方案。

<cfheader name="Content-Disposition" value="attachment;filename=filename.xls">
<cfcontent variable="#spreadsheetReadBinary(mySS)#"  type="application/msexcel">

答案 1 :(得分:0)

尝试:

<cfcontent variable="#mySS#">

您可能也想设置type属性,以便浏览器知道它不是HTML。

相关问题