So, it was asked on twitter if cfspreadsheet could read a csv file. I quickly looked at the docs and it appeared to me that it could. The docs even had this example..
However, if you try and do that you get this error:
An error occurred while reading the Excel: java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream.
So, what I figured out was that cfspreadsheet type="csv" just converts the read xls document into csv format. Not sure how usefull that is.
So, I started digging into a possible solution. Then I stumbled into something. I ran into a post that talked about using cfhttp to load the csv. So, that got me thinking and I ended up with this.
<cfloop query="csvdata" >
<cfloop list="#csvdata.columnlist#" index="i">
I was shocked that the isQuery returned true. So, since it uses the first row as the column names I write some code to loop over the data and out put it. I honestly didn't think that this would work. I just get totally excited when something that I thought would be hard became super easy thanks to ColdFusion.
I have only ran this against ColdFusion 9 so I am not sure about backwards compatibility.
UPDATE: If the column name contains a space an error will be thrown. The error happens in the cfhttp tag call so you can't correct them post call. Make sure that if you are doing this that your first row contains text that are column name formatted. I.e... use "my_date" instead of "my date".
Till next time...