将数据添加到数组时,其中一个元素的值为逗号。值的一个示例是“103,96和90处的修剪标记”。数组元素中的逗号分隔电子表格
使用以下代码将数组元素添加到电子表格对象,如上所述,partdescription元素使其数据跨越电子表格中的多列。它作为单独的元素处理,而不是一个。
<!---Create file name variable--->
<cfset filenametouse = 'PartLevel_Report' />
<!---Set directory and full file path--->
<cfset theDir = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<!---Attach file extension to full file path and file name--->
<cfset theFile = theDir & filenametouse & ".xls" />
<cflock name="fileActionSentItems" type="exclusive" timeout="30" throwontimeout="true">
<cfset SpreadsheetObj = spreadsheetNew()>
<cfset fcol = {}>
<cfset fcol.dataformat = "@">
<!---Create the column headings--->
<cfset SpreadsheetAddRow(SpreadsheetObj, "Part ##, Reorder ##, Description, Bin ##, Current Inv., Staged, Allocations, Available Inv., Shelf Count, Total Shipped, Total ## of Stores, Total Ordered, Avg. Per Store, Lead Time (in days), Low Water Mark, Total ## of Stores Remaining")>
<cfoutput query="getParts" group="partnum">
<cfset aColumns = [ partnum , shortchar08 , partdescription , binlist , inventory.currinv , staged.stagedqty , alloc.allocqty , available , shelfCount , shipdtl.shipqty , getNumberofStores.numStores , tordered , APS, paddedLeadTime, LWM , storesRemain] />
<!---add the column data to the spreadsheet--->
<cfset SpreadsheetAddRow(SpreadsheetObj, ArrayToList(aColumns)) />
</cfoutput>
<!---Generate the spreadsheet--->
<cfspreadsheet action="write" filename="#theFile#" name="SpreadsheetObj" sheetname="Sheet1" overwrite="true" />
我该如何缓解这个问题?
解决方法:我将一个变量设置为partdescription,所有逗号都用分号替换。现在数据全部出现在同一列中:
<cfset cleanDesc = rereplace(partdescription, ",", ";", "all")>
<cfset aColumns = [ partnum , shortchar08 , cleanDesc , binlist , inventory.currinv , staged.stagedqty , alloc.allocqty , available , shelfCount , shipdtl.shipqty , getNumberofStores.numStores , tordered , APS, paddedLeadTime, LWM , storesRemain] />
看到这个:http://cfsimplicity.com/30/workaround-for-spreadsheetaddrow-limitation-when -column-values-containing-commas – 2012-03-01 19:50:36
谢谢你的指导,Dan;然而,我不明白如何翻译这个例子来适应我的情况。我没有使用cfscript,而是在查询中构建电子表格。我用更多的编码来编辑我的原始问题。 – aparker81 2012-03-01 20:19:41
@ aparker81 cfscript to cfml非常容易。而不是x = y(z);它是'所以你应该能够关注@Dan A.发布的内容。 –
Henry
2012-03-02 00:46:52