クライアントから Excel ファイルを受け取り、それらから csv ファイルを作成する必要があります。私の問題は、Excel ファイルの値が、コピーするだけで csv ファイルを作成する基準と一致しないことです。ファイルの作成中に、値を取得して正しい順序に並べる必要があります。CFのライブドキュメントを読みましたが、うまくいくものは見つかりませんでした。
構造体を作成してその中のデータを引き出し、構造体に基づいてcsvファイルを作成することを考えていましたが、これまでにこのようなことをしたことがなく、それが可能かどうかさえわかりません。構造体の代わりに listGetAt を使用することも考えましたが、まだ試していません。
誰かが前にこのようなことをしましたか?同じ問題を抱えた 2 番目のクライアントが発生した場合、これが将来の問題になると思われるため、できるだけ少ない値をハードコーディングしようとしています。
更新(過去数日間、コードを大幅に変更したため、これが現在のものです)
<cfset DataDirectory = "E:\testfolder\test.xlsx">
<cfspreadsheet action="read" src="#DataDirectory#" excludeHeaderRow="true" headerrow="1" query="queryData">
<cfquery name="contact" datasource="#ds#">
select ClientBrandID
from ClientBrands
where surveyReferralID IN
(select surveyReferralID from clientAdmin where username = '#res#')
</cfquery>
<cfscript>
dataFile = structNew();
StructInsert(datafile,"ClientBrandID",contact.ClientBrandID);
StructInsert(datafile,"surveyType", queryData.surveyType);
</cfscript>
<cfscript>
///We need an absolute path, so get the current directory path.
theFile= "E:\testfolder\NewTest.csv";
//Create a new Excel spreadsheet object and add the query data.
theSheet = SpreadsheetNew("PatientData");
SpreadsheetAddRow(theSheet, "ClientBrandID,SurveyType,Location,ClientContactID,FirstName,LastName,HomePhone,WorkPhone,CellPhone,Email"); <!---This is the header of the new CSV --->
SpreadsheetAddRows(theSheet, "datafile.clientbrandid, datafile.surveytype"); <!--- This is my latest failed attempt. Tried to pass in data from my struct, probably the quotes are the issue but haven't tried it without them --->
</cfscript>
<!--- Write the spreadsheet to a file, replacing any existing file. --->
<cfspreadsheet action="write" filename="#theFile#" format="csv" name="theSheet" overwrite=true >
テスト フォルダー内のすべてのファイルを処理するには、これらのすべての操作を cfloop で実行する必要があります。現在、他のことをする前に、目前の問題を修正するために単一のファイルをハードコーディングしています。また、その間にファイルのすべての値を処理する必要がある別のループがありません。<cfloop query='queryData'>
これは、cfspreadsheet から取得したクエリのようなものである必要があります。