Be VERY CAREFUL with this code, because CF "eats"
multiple contiguous delimiters.
ListLen("foo,bar,candy") is 3, but
ListLen("foo,,candy") is *2*, and
ListGetAt("foo,,candy",3) will return an error.
The last time I had to work with CSV files
containing null values I did this:
!--- For each row, parse the columns into an
array: ---
CFSET aThisRow = ArrayNew(1)CFLOOP
List="#TheFile#" Index="CurRow"
Delimiters="#crlf#"cfscript
while (len(CurRow)) {tabPos =
find(tab,CurRow);if (tabPos is 0)
{aThisRow[CurCol]=CurRow;CurRow="";}
else if (tabPos is 1)
{aThisRow[CurCol]="";CurRow=mid(CurRow,2,len(CurRow));}
else
{aThisRow[CurCol]=left(CurRow,tabPos-1);CurRow=mid(CurRow,tabPos+1,len(CurRow));}CurCol=CurCol+1;}
/cfscript
!--- here i did the import based on the
column number index into the array ---
/CFLOOP
HTH
Daryl
- Original Message -
From: Jones, Matt
To: '[EMAIL PROTECTED]'
Sent: Monday, June 11, 2001 2:55 PM
Subject: RE: [KCFusion] Uploading CSV
cfset EndLine = Chr(10)
Chr(13)
cfset listDelim = ","
cfloop list="#RawFile#" index="CurData"
delimiters="#EndLine#"
!--- Name could be accessed by
#listGetat(CurData,1,listDelim)# ---
!--- Faxnumber could be accessed
by #listGetat(CurData,2,listDelim)# ---
!--- Put your insert query here
---
/cfloop
-Original Message-From: Rick Eidson
[mailto:[EMAIL PROTECTED]]Sent: Monday, June 11, 2001 2:44
PMTo: KCCFUG ([EMAIL PROTECTED])Subject: [KCFusion]
Uploading CSV
I need to upload a CSV file and
enter its field values into a database.
I can read the file and output
it
cffile
destination="e:\WebSites\KCHost\Fax" action="UPLOAD"
nameconflict="overwrite" filefield="XFile"
cffile action="READ" file="e:\WebSites\KCHost\Fax\#FILE.ServerFile#" variable="RawFile"
cfquery datasource="enews" name="Update"
INSERT INTO
Fax
(Name)
VALUES('#RawFile#')
/cfquery
This puts into one field. But how
can Read each field
The fields would be Name, Faxnumber
Rick
Eidson