cfspreadsheet 在逗号分隔行中转义逗号插入

发布于 2024-11-24 13:29:33 字数 459 浏览 1 评论 0原文

用于向 Coldfusion 电子表格添加行的函数是 SpreadsheetAddrow,它接受“以逗号分隔的单元格条目列表,每列一个”的数据。

我的一些数据中有逗号。如何转义数据中的逗号而不转义列表中的逗号?

我当前正在创建一个包含该行内容的数组,然后将其转换为列表以添加到电子表格中:

    <cfset row = ArrayNew(1)>
    <cfloop list="#structKeyList(setRecord.columns)#" index="key">
        <cfset ArrayAppend(row, "#Evaluate(key)#")>
    </cfloop>
    <cfset spreadsheetAddRow(xlsObj, "#ArrayToList(row)#")>

The function for adding a row to a coldfusion spreadsheet is SpreadsheetAddrow which accepts data as "A comma delimited list of cell entries, one per column."

Some of my data has commas within it. How do I escape the commas within my data without escaping the commas in the list?

I am currently creating an array with the contents of the row, then converting it to a list to add to the spreadsheet:

    <cfset row = ArrayNew(1)>
    <cfloop list="#structKeyList(setRecord.columns)#" index="key">
        <cfset ArrayAppend(row, "#Evaluate(key)#")>
    </cfloop>
    <cfset spreadsheetAddRow(xlsObj, "#ArrayToList(row)#")>

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

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

发布评论

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

评论(3

抠脚大汉 2024-12-01 13:29:33

看起来指定不同分隔符的能力不是还支持。由于您已经在循环,您也可以跳过数组并使用 相反,SpreadsheetSetCellValue。您也应该能够消除评估()。

<cfset cols = structKeyArray(yourStruct) >
<cfloop from="1" to="#arrayLen(cols)#" index="c">
   <cfset SpreadsheetSetCellValue(xlsObj, yourStruct[ cols[c] ], lastRow, c)>
</cfloop>
<cfset lastRow++>
...

更新:但是,如果基础对象是查询而不是结构,那么使用 CfSimplicity 的 SpreadSheetAddRows 建议会更有效。

Looks like the ability to specify a different delimiter is not supported yet. Since you are already looping, you may as well skip the array and use SpreadsheetSetCellValue instead. You should be able to eliminate the evaluate() as well.

<cfset cols = structKeyArray(yourStruct) >
<cfloop from="1" to="#arrayLen(cols)#" index="c">
   <cfset SpreadsheetSetCellValue(xlsObj, yourStruct[ cols[c] ], lastRow, c)>
</cfloop>
<cfset lastRow++>
...

Update: However, if the base object is a query, not a structure, then it is more efficient to use CfSimplicity's suggestion of SpreadSheetAddRows.

西瓜 2024-12-01 13:29:33

如果要添加到工作表的数据位于查询对象(记录集)中,那么最简单的解决方案是使用 SpreadSheetAddRows()(而不是 SpreadSheetAddRow - 单数)。

<cfset SpreadSheetAddRows( xlsObj,query )>

工作表列是从查询列映射的,因此数据中的逗号并不重要。

即使数据采用其他格式或者您仅添加一行,将其转换为查询对象也是解决该问题的有效方法,请参阅 http://cfsimplicity.com/30/workaround-for-spreadsheetaddrow-limitation-when-column-values-contain-commas

If the data you want to add to the sheet is in a query object (recordset) then the simplest solution is to use SpreadSheetAddRows(), (as opposed to SpreadSheetAddRow - singular).

<cfset SpreadSheetAddRows( xlsObj,query )>

The sheet columns are mapped from the query columns, so commas in the data won't matter.

Even if the data is in another format or you are only adding a single row, converting it to a query object is an effective way of getting round the issue, see http://cfsimplicity.com/30/workaround-for-spreadsheetaddrow-limitation-when-column-values-contain-commas

赤濁 2024-12-01 13:29:33

您可以将逗号替换为字符“#130;” (参见来源:https://www.petefreitag.com/cheatsheets/ascii-codes/ ),它看起来与逗号相同,但不会产生任何问题。

You can replace the commas with the character "#130;" (see the source: https://www.petefreitag.com/cheatsheets/ascii-codes/), which looks the same as comma but doesn't create any problems.

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