2

When adding data to an array, one of the elements has commas in its value. An example of the value is "Trim marks at 103, 96, and 90".

Using the following code to add the array elements to the spreadsheet object, the partdescription element, as described above, has its data span multiple columns in the spreadsheet. It is handled as separate elements and not one.

<!---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" />

How may I alleviate this issue?

Solved: I set a variable to the partdescription with all commas replaced with semicolons. Now the data appears all in the same column:

 <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] />
4

4 回答 4

2

你试过SpreadsheetAddRows()吗?传递整个查询?假设这SpreadsheetAddRows()不只是SpreadsheetAddRow()在下面调用,也许这将是一种解决方法。

由于SpreadsheetAddRow()不接受大多数 CF 列表功能支持的可选分隔符,我想您也可以将逗号转义为其他内容,然后使用spreadsheetsetcellvalue()?将其替换为逗号

您可能需要向 Adob​​e 提交功能请求,以获取该SpreadsheetAddRow()功能的可选分隔符。

于 2012-03-01T20:48:58.763 回答
1

尝试使用“listQualify()”首先确保您的列表元素 - 包含逗号的元素 - 不会弄乱列表长度。

于 2012-03-01T21:03:27.850 回答
1

根据 Adob​​e 工程师关闭Dan A. 的链接

来自 Adob​​e 的 Kunal 指出了一种更直接的解决方法,即将变量用单引号括起来,然后用双引号括起来

所以……紧接着<cfset aColumns = [ ... ]>

<!--- wrap element with single quote if it contains a comma --->
<cfloop from="1" to="#arrayLen(aColumns)#" index="i">
    <cfif aColumns[i] CONTAINS ','>
        <cfset aColumns[i] = "'#aColumns[i]#'">
    </cfif>
</cfloop>

<cfset SpreadsheetAddRow(SpreadsheetObj, ArrayToList(aColumns)) />
于 2012-03-02T01:01:57.620 回答
0

正如亨利所说,将变量括在单引号中对我有用,除非最后一个字符是逗号。

<cfset SpreadsheetAddRow(SpreadsheetObj, "'col1,','col2'" />

所以我为每个单元格的值添加了一个空格,如下所示:

<cfset SpreadsheetAddRow(SpreadsheetObj, "'col1, ','col2 '" />
于 2018-02-23T22:33:34.977 回答