OK, since Excel incorrectly formats CSV files (it does not put quotes around all fields, which is the standard), ODBC has problems with data formats. I won't bore you with the details here.
Anyway, our solve was to try and correct the CSV file before we query it. So, this is what we need to do.
Here are two sample data sets we need to convert:
DataSet 1
-----------
Column1,Column2,Column3
aaaaa,bbbbb,ccccc
ababa,"baba, baba",cdcdcd
ffffff,,dddddd
(notice that the 2nd row, 2nd column has quotes around the field since there is a comma in that field)
DataSet 2
-----------
"Column1","Column2","Column3"
"ssssss","tttttt","uuuuuu"
"vvvvvvvv","wwwwww","xxxxxx"
"yyyyy","zzzzzz","1111111"
(this data set is properly formated, with quotes around all fields)
We will get CSV files in both formats, so we need to account for both.
So, what we need to do is:
- change all commas to "," unless that comma is already between quotes. Then, you would have to replace ," with ","...as in the DataSet 1
- add " to the beginning and end of the line
- do the above steps only if the file is not formatted like Dataset 2
Is this possible? I don't even know where to begin on having CF perform a find and replace this complex.
by: pinaldavePosted on 2004-06-16 at 12:45:23ID: 11328193
Try to use regular expressions. .com/coldf usion/6.1/ htmldocs/ f uncta72.ht m#wp111157 7
http://livedocs.macromedia
Regards,
---Pinal