cfspreadsheet 在逗号分隔行中转义逗号插入
用于向 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来指定不同分隔符的能力不是还支持。由于您已经在循环,您也可以跳过数组并使用 相反,SpreadsheetSetCellValue。您也应该能够消除评估()。
更新:但是,如果基础对象是查询而不是结构,那么使用 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.
Update: However, if the base object is a query, not a structure, then it is more efficient to use CfSimplicity's suggestion of
SpreadSheetAddRows
.如果要添加到工作表的数据位于查询对象(记录集)中,那么最简单的解决方案是使用 SpreadSheetAddRows()(而不是 SpreadSheetAddRow - 单数)。
工作表列是从查询列映射的,因此数据中的逗号并不重要。
即使数据采用其他格式或者您仅添加一行,将其转换为查询对象也是解决该问题的有效方法,请参阅 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).
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
您可以将逗号替换为字符“#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.