I have a page that creates a table from a database, and I want to offer a CSV version of that table for download. I used <cffile> to create the CSV, and it works perfectly, except that some of the cells may contain commas, which throws off my CSV file.
Here’s my code:
<cffile action="write"
file="#expandpath(".")#\\filename.csv"
output="Title,Nominating Agency,Nominee Agency,State,Categories,Finalized"
addnewline="yes">
<cfoutput query="nomadmin">
<cffile action="append"
file="#expandpath(".")#\\filename.csv"
output="#trim(nom_title)#,#trim(user_org)#,#trim(nom_agency)#,#trim(nom_state)#,#trim(nom_category)#,#iif(finalized eq 1,DE("Yes"),DE("No"))#"
addnewline="yes">
[...html code for table here...]
</cfoutput>
Is there any way to escape the commas in the column values to keep them from throwing off my columns in the CSV?