I am using CFSPREADSHEET to read an XLS file into a query. Then reordering the columns as necessary. However, the query-of-query I am using retains alphabetical column order.
The XLS file has the fields in the correct order, but when converted to a query the fields are alphabetized.
I output the results to a CSV using this nifty UDF and the fields are still alphabetized as proof that the q-of-q is not adhering to my request.
In order to correct this issue I'm trying to use a q-of-q to reformat the columns in their proper order.
<cfspreadsheet action="read" src="#local.tmpPath##local.tmpFile#" excludeheaderrow="true" headerrow="1" sheet="1" query="local.qTemp" />
<!--- Change column order around as necessary --->
<cfquery name="local.qTemp" dbtype="query">
SELECT
Name, Address, City
FROM
[local].qTemp
</cfquery>
<cfset local.newCSV = QueryToCSV(
query = local.qTemp,
fields = local.qTemp.columnlist,
createHeaderRow = true,
delimiter = '|'
) />
<cffile action="write" charset="windows-1252" file="#local.tmpPath#foo.csv" output="#replace(local.newCSV, """", "", "ALL")#" nameconflict="overwrite" />
The column order when I output is:
Address,City,Name
Instead of the query order:
Name,Address,City
I read this post about the topic, but it didn't address my issue specifically (unless I am reading it wrong).