首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用dataformat时逗号无效

使用dataformat时逗号无效
EN

Stack Overflow用户
提问于 2013-01-18 18:04:19
回答 2查看 352关注 0票数 2

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

代码语言:javascript
复制
<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>

我得到的错误是:

代码语言:javascript
复制
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">

出于某种原因,它不喜欢逗号,即使根据documentation它是有效的。如果我去掉逗号,它是有效的,但我需要它来进行千位分组。

有人遇到过这种情况吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-18 18:25:03

在ColdFusion中,#是保留字符。为了逃脱它,你必须加倍它们才能逃脱:

代码语言:javascript
复制
<cfset format.dataformat = "##,######0.00">

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

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

代码语言:javascript
复制
<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>
票数 8
EN

Stack Overflow用户

发布于 2013-01-18 18:26:34

应该是这样的

代码语言:javascript
复制
<cfset format = StructNew()>
<cfset format.dataformat = "##,####0.00">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14396499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档