经典 ASP 写入 csv 文件,不将数据写入单独的列

发布于 2024-10-14 21:23:07 字数 721 浏览 1 评论 0原文

我有一个创建 CSV 文件的经典 ASP 脚本,但它无法正确写入单独的列。它基本上将所有内容都写入第一列。

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)

其中 head 是一个变量,

Head = "Date, Name, Recipe Name, Email, Joined Mailing List?, Site, Suggestion Content"

如果我使用

set csvfile = FSO.CreateTextFile(filesavepath, true)

它,它可以工作,但我需要使用

set csvfile = FSO.CreateTextFile(filesavepath, true,true)

一段时间,因为我需要在 CSV 中写入外来符号。当然必须有一种方法来保持这一点并保持列完好无损?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

打小就很酷 2024-10-21 21:23:07

由于数据行的开头和结尾有双引号,因此整行将被解释为一个字段。

As you have double quotes at the start and end of your data line the whole line is interpreted as one field.

暗藏城府 2024-10-21 21:23:07

做了一些挖掘,虽然这有点违反直觉,但如果您使用 TAB 字符分隔字段,那么 Excel 似乎可以很好地解析出 Unicode 文件。例如,这对我有用:

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

希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文