I'm trying to parse a CSV using the CFCSV custom tag. Here's my CFML code:
<cfset data = fileRead( "inputtest.csv", "utf-8" ) />
<cfcsv action="parse" data="#data#" variable="csv" hascolumnnames="true" delimiter="," />
<cfloop query="csv">
<cfoutput>#csv.name#</cfoutput>
</cfloop>
.. and my test CSV:
"Email","Name","Address1","Address2","City","State","ZIP","Country","Phone"
"[email protected]","Some Dude","3129 golden bridge ave",,"somecity","somestate","somezip","usa","1234567890"
The error I get is:
column [NAME] not found in query, columns are [Email,Name,Address1,Address2,City,State,ZIP,Country,Phone]
If I change the loop to output anything other than name, it works. But I can't get the name. Even changing the columname from Name
to TheName
results in the same error:
column [THENAME] not found in query, columns are [Email,TheName,Address1,Address2,City,State,ZIP,Country,Phone]
But again, I have no problem outputting the email address or any other column. Changing the location of the column in the CSV and/or changing from cfloop query
plus cfoutput
to just cfoutput query
has no effect.
If I cfdump
the query, the column is there.
I was able to reproduce the problem by adding a newline at the start of the CSV file, but you could see this same error anytime there is a problem parsing the column header line.