Search code examples
csvcoldfusioncfloopcffile

Getting strange characters when using cffile to loop over a csv


I' am on ColdFusion 11. I' am using the following code to loop over a CSV File and output the first row in the loop.

<cffile action="read" file="C:\inetpub\wwwroot\test\file.csv" variable="csvfile">
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#"> 
    <cfoutput>#listgetAt('#index#',1, ',')#</cfoutput>
</cfloop>

It's outputting something strange characters. Here is the screenshot. enter image description here

My CSV Structure

enter image description here

Please help!


Solution

  • You are reading an XLSX (MS Excel) file that has had its changed to CSV.

    Notice how it starts with PK and is followed by .xml. This is a PK ZIP of XML, which is the native format for XLXS.

    As a test, you can rename it to .zip and unzip it. You will see lots and lots of folders and .xml files

    How to correct

    You need to save as CSV, not just rename to CSV