使用dataformat时逗号无效

Ali*_*ias 2 coldfusion dataformat export-to-excel coldfusion-10 cfspreadsheet

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

<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>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

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">
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它不喜欢逗号,即使它根据文档有效.如果我拿出逗号,它可以工作,但我需要它为成千上万的分组.

谁遇到过这个?

BKK*_*BKK 8

在ColdFusion中,#是保留字符.要逃避它,你必须将它们加倍以逃避它们:

<cfset format.dataformat = "##,######0.00">
Run Code Online (Sandbox Code Playgroud)

愚蠢的是,他们没有在文档中说明这一点,或者使用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>
Run Code Online (Sandbox Code Playgroud)