epipko
03/10/2022, 6:04 PMCUSTOMER_ID,DIVISION_ID,STYLE_ID,QUANTITY
AMAZON,YMS,Y15CXWE,31
AMAZON,YMS,Y15CXWE,85
,,,
,,,
,,,
,,,
Question: how can I remove lines with commas ONLY in them?Adam Cameron
Adam Cameron
deactivateduser
03/10/2022, 6:12 PMAdam Cameron
deactivateduser
03/10/2022, 6:15 PMdeactivateduser
03/10/2022, 6:21 PMepipko
03/10/2022, 6:30 PMepipko
03/10/2022, 6:30 PM<cfspreadsheet action="read" src="#xlsFile#" query="qryExcel">
epipko
03/10/2022, 6:30 PM<cfoutput query="qryExcel">
<cfset line = "#col_1#,#col_2#,#col_3#,#col_4#,#col_5#>
<cffile action="append" file="#csvFile#" output="#line#">
</cfoutput>
Michael Schmidt
03/10/2022, 6:32 PMepipko
03/10/2022, 6:33 PMepipko
03/10/2022, 6:33 PMMichael Schmidt
03/10/2022, 6:41 PMDavid Buck
03/10/2022, 7:16 PM<cfspreadsheet>
has a format="csv"
option if you're only using it to do the conversion, e.g.:
<cfspreadsheet action="read" src="#xlsFile#" format="csv" name="csvdata">
<pre><cfset writeOutput(csvdata)></pre>
That will exclude any rows that don't have data in them.epipko
03/10/2022, 8:54 PMepipko
03/10/2022, 9:22 PMepipko
03/10/2022, 9:32 PMepipko
03/10/2022, 9:32 PMepipko
03/10/2022, 9:42 PMepipko
03/10/2022, 9:43 PM<cfoutput query="qryExcel">
<cfset line = "#col_1#,#col_2#,#col_3#,#col_4#">
<cfif TRIM(REReplace(line, ",", "","ALL")) NEQ "">
<cffile action="append" file="#csvFile#" output="#line#">
</cfif>
</cfoutput>
David Buck
03/10/2022, 10:08 PMreReplace
. You can replace all of the code in your above snippets with this:
<cfspreadsheet action="read" src="#xlsFile#" format="csv" name="csvdata">
<cfset filewrite(csvFile, rereplace(csvdata, "((^|[\r\n]+),+)+(([\r\n]+)|$)", "\4", "all"))>
That's a bit more elegant, imo. And, as an added bonus, it automatically puts quotes around values with commas so they won't be interpreted as additional columns.epipko
03/10/2022, 11:24 PM