Coldfusion电子表格单元格格式

时间:2013-08-21 18:03:05

标签: excel coldfusion spreadsheet

我需要从查询中生成带有coldfusion 10的excel电子表格。到目前为止它的工作正常,除了表格的标题。它们是动态生成的[月份] 2012年12月。当我添加标题列时,我会以“01/12 / 2013”​​之类的日期格式获取它。还有其他类型的日期格式和其他类型的单元格格式。如何强制单元格格式化为字符串。当你添加单引号时。

这是我的代码:

<cfset VARIABLES.vcFilename = "billtotals_" & DateFormat(Now(), "yyyymmdd") & "-" & TimeFormat(Now(), "HHmmss") & ".xls">
<cfset VARIABLES.sheet = SpreadSheetNew( "Summary" )>
<cfset VARIABLES.columns = arrayToList(GetBillPremTotals.getMeta().getColumnLabels())>
<cfset SpreadSheetAddRow( VARIABLES.sheet,VARIABLES.columns)>

<cfset format1 = StructNew()>
<cfset format1.bold = "true">
// tried this just for kicks doesn't work <cfset format1.dataformat = "'">
// tried this converts to a number <cfset format1.dataformat = "text">
<cfset SpreadsheetFormatRow(VARIABLES.sheet, format1, 1)> 

<cfset SpreadSheetAddRows(VARIABLES.sheet,GetBillPremTotals)>

<cfset SpreadSheetAddRows(VARIABLES.sheet,GetBillPremGrandTotals)>
<cfset VARIABLES.sheetAsBinary = SpreadSheetReadBinary(VARIABLES.sheet)>

<cfheader name="Content-Disposition" value="attachment; filename=#Chr(34)##VARIABLES.vcFilename##Chr(34)#">
<cfcontent type="application/msexcel" variable="#VARIABLES.sheetAsBinary#" reset="true">

这是一个包含查询分析器数据的表,在浏览器中以html格式显示正常

No          November 2012                           December 2012                           January 2013                            February 2013
----------- --------------------------------------- --------------------------------------- --------------------------------------- ---------------------------------------
25          60117.56000                             61515.17000                             60791.62000                             60745.29000
28          1564.69000                              1564.69000                              1564.69000                              1590.44000
30          110599.11000                            173954.08000                            178064.11000                            172892.65000

提前谢谢你, 颊

1 个答案:

答案 0 :(得分:1)

这就是诀窍。

<cfset format1.dataformat = "mmmm yyyy">