1

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

这是我的代码:

<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

提前谢谢你,吉娜

4

1 回答 1

1

这成功了。

<cfset format1.dataformat = "mmmm yyyy">
于 2013-08-21T18:47:32.260 回答