2

这是我将查询输出到电子表格的代码。

<cfscript> 
  //Use an absolute path for the files. ---> 
  theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
  theFile=theDir & "getTestInv.xls"; 
  //Create an empty ColdFusion spreadsheet object. ---> 
  theSheet = SpreadsheetNew("invoicesData"); 
  //Populate the object with a query. ---> 
  SpreadsheetAddRows(theSheet,getTestInv);
</cfscript>

<cfset format = StructNew()>
<cfset format.dataformat = "#,###0.00">
<cfset SpreadsheetFormatColumn(theSheet,format,10)

<cfspreadsheet action="write" filename="#theFile#" name="theSheet" sheetname="getTestInv" overwrite=true>

我得到的错误是:

Invalid CFML construct found on line 125 at column 32.
ColdFusion was looking at the following text:

,

The CFML compiler was processing:

An expression beginning with /", on line 125, column 30.This message is usually caused by a problem in the expressions structure.
A cfset tag beginning on line 125, column 4.
A cfset tag beginning on line 125, column 4.

125: <cfset format.dataformat = "#,###0.00">

出于某种原因,它不喜欢逗号,即使根据文档它是有效的。如果我把逗号去掉,它会起作用,但我需要它来进行数千个分组。

有人遇到过这个吗?

4

2 回答 2

8

在 ColdFusion 中,# 是保留字符。要逃脱它,您必须将它们加倍以逃脱它们:

<cfset format.dataformat = "##,######0.00">

愚蠢的是,他们既没有在文档中说明这一点,也没有使用 9s 而不是 #s 遵循 ColdFusion 的格式化规则。

这是我完整的独立测试代码:

<cfset myQuery = QueryNew('number')>
<cfset newRow = QueryAddRow(MyQuery, 2)> 
<cfset temp = QuerySetCell(myQuery, "number", "349348394", 1)> 
<cfset temp = QuerySetCell(myQuery, "number", "10000000", 2)> 

<cfscript> 
  //Use an absolute path for the files. ---> 
  theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
  theFile=theDir & "getTestInv.xls"; 
  //Create an empty ColdFusion spreadsheet object. ---> 
  theSheet = SpreadsheetNew("invoicesData"); 
  //Populate the object with a query. ---> 
  SpreadsheetAddRows(theSheet,myQuery,1,1);
</cfscript>


<cfset format = StructNew()>
<cfset format.dataformat = "##,######0.00">
<cfset SpreadsheetFormatColumn(theSheet,format,1)>

<cfspreadsheet action="write" filename="#theFile#" name="theSheet" sheetname="theSheet" overwrite=true>
于 2013-01-18T10:25:03.397 回答
0

应该是这样的

<cfset format = StructNew()>
<cfset format.dataformat = "##,####0.00">
于 2013-01-18T10:26:33.567 回答