Reputation: 6533
I have a classic ASP script creating a CSV file, but it isn't writing correctly to separate columns. It's basically writing it all to the first column.
dim filesavepath
filesavepath = site_pathRoot & "dynamic/pdf/" & fileName & ".csv"
set FSO = Server.CreateObject("scripting.FileSystemObject")
set csvfile = FSO.CreateTextFile(filesavepath, true,true)
csvfile.writeLine(Head)
Where head is a variable as such
Head = "Date, Name, Recipe Name, Email, Joined Mailing List?, Site, Suggestion Content"
If I use
set csvfile = FSO.CreateTextFile(filesavepath, true)
It works but I needed to use
set csvfile = FSO.CreateTextFile(filesavepath, true,true)
a while back because I need to write foreign symbols in the CSV. Surely there must be a way to keep this and keep the columns intact?
Upvotes: 1
Views: 4340
Reputation: 21
As you have double quotes at the start and end of your data line the whole line is interpreted as one field.
Upvotes: 2
Reputation: 2468
Done a bit of digging, and although it's a bit counter-intuative, but if you delimit your fields with the TAB character, then Excel seems to parse out Unicode files quite nicely. e.g. this works for me:
dim filesavepath
filename = "bla"
filesavepath = fileName & ".csv"
QUOT = """"
COMMA = " " '//this is now a TAB character
Head = "Date Name"
line1 = "2001-01-01" & COMMA & QUOT & "Frank" & QUOT
line2 = "2002-01-01" & COMMA & QUOT & "Jan" & QUOT
set FSO = CreateObject("scripting.FileSystemObject")
set csvfile = FSO.CreateTextFile(filesavepath, true, true)
csvfile.writeLine(Head)
csvfile.writeLine(line1)
csvfile.writeLine(line2)
csvfile.writeLine(QUOT)
csvfile.close
Hope this helps.
Upvotes: 0