CFScript Evaluate() 在循环中抛出错误

发布于 2024-12-25 01:33:22 字数 825 浏览 1 评论 0原文

我正在尝试使用 cfspreadsheet 将一堆 get 函数转储到电子表格中 - 我决定创建一个列表并循环遍历它,而不是传递每个单独的函数。我认为我在这里错误地使用了 Evaluate() ,但我不确定实现此目的的最佳方法是什么。任何建议/优化将不胜感激,因为我的 Cold-Fu 不是那么好。

抛出的错误是变量GETFIELDS未定义。

<cfset var fields = "Function1,Function2" />
<cfspreadsheet action="read" src="#strDestinationPath#information.xls" name="xlsInfo" headerrow="1" />
<cfset var row = xlsData.rowcount + 1 />
<cfset var count = 1 />
<cfloop list="fields" index="f" delimiters=",">
   <cfscript>
    SpreadsheetSetCellValue(xlsInfo,Evaluate('get' & f & '()'),row,count);
    count++;
   </cfscript>  
</cfloop>   
<cfspreadsheet action="write" overwrite="true" filename="#strDestinationPath#information.xls" name="xlsInformation" />

I'm attempting to dump a bunch of get functions into a spreadsheet using cfspreadsheet - instead of passing each individual function, I've decided to create a list and loop through it. I think I am using Evaluate() incorrectly here, but I'm not sure what the best way to accomplish this is. Any suggestions/optimizations would be appreciated, as my Cold-Fu isn't that great.

Error thrown is Variable GETFIELDS is undefined.

<cfset var fields = "Function1,Function2" />
<cfspreadsheet action="read" src="#strDestinationPath#information.xls" name="xlsInfo" headerrow="1" />
<cfset var row = xlsData.rowcount + 1 />
<cfset var count = 1 />
<cfloop list="fields" index="f" delimiters=",">
   <cfscript>
    SpreadsheetSetCellValue(xlsInfo,Evaluate('get' & f & '()'),row,count);
    count++;
   </cfscript>  
</cfloop>   
<cfspreadsheet action="write" overwrite="true" filename="#strDestinationPath#information.xls" name="xlsInformation" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2025-01-01 01:33:22

cfloop 需要一个项目列表 作为参数。

尝试更改为

<cfloop list="fields" index="f" delimiters=",">

<cfloop list="#fields#" index="f" delimiters=",">

<cfloop list="Function1,Function2" index="f" delimiters=",">

cfloop expects a list of items as an argument.

Try changing from

<cfloop list="fields" index="f" delimiters=",">

to

<cfloop list="#fields#" index="f" delimiters=",">

or to

<cfloop list="Function1,Function2" index="f" delimiters=",">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文