配列にデータを追加するとき、いずれかの要素の値にコンマが含まれています。値の例は、「103、96、および 90 のトリム マーク」です。
次のコードを使用して配列要素をスプレッドシート オブジェクトに追加すると、上記のように、partdescription 要素のデータがスプレッドシート内の複数の列にまたがります。1 つの要素ではなく、個別の要素として扱われます。
<!---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] />