使用多行字段在 vbscript 中编写 csv

writing csv in vbscript with multiline fields

在过去的 4 个小时里,我一直在努力解决这个问题,老实说,我真的很累……我正在尝试通过 vbscript 在几个字段中使用多行编写一个 CSV 文件……我认为它会是简单易行......不是这样......我的原始代码是

summary = "This is my brief summary"
description = "Hello" & vbCrLf & "Today, I am going to describe my issue."
reference_id = "0000102203"

Set fso = CreateObject("Scripting.FileSystemObject")
Set csv = fso.CreateTextFile(download_file_name,True)

csv.WriteLine summary & "," description & "," & "Consulting" & "," & reference_id 
csv.close
set csv = Nothing

我想做的就是创建一个 csv,当我使用 excel 打开文件时会显示为

This is my brief summary| Hello                                   |Consulting| 0000102203    
                        | Today, I am going to describe my issue. |   

通过多次尝试将 vbCrLf 替换为 vbCr,vbLf, chr(10), chr(13), "\n", "\n", "\r","\r"堆更多

This is my brief summary| Hello
Today, I am going to describe my issue. |Consulting|  0000102203

有没有办法真正解决这个问题?

谢谢

没有实际标准。这个 RFC 在 CSV 被发明之后就出现了。所以你可以做你想做的事,但你还需要代码来读取你自己的标准,因为其他工具不需要。将CR实现为特殊字符(代码222对我来说有历史意义-SurveyCraft)导入后替换为CR。

来自 https://www.rfc-editor.org/rfc/rfc4180 (also see https://en.wikipedia.org/wiki/Comma-separated_values)

  1. Definition of the CSV Format

While there are various specifications and implementations for the CSV format (for ex. [4], [5], [6] and [7]), there is no formal
specification in existence, which allows for a wide variety of
interpretations of CSV files. This section documents the format that seems to be followed by most implementations:

  1. Each record is located on a separate line, delimited by a line break (CRLF). For example:

       aaa,bbb,ccc CRLF
       zzz,yyy,xxx CRLF
    
  2. The last record in the file may or may not have an ending line break. For example:

       aaa,bbb,ccc CRLF
       zzz,yyy,xxx
    

好吧,我的头在键盘上敲了 4 个小时之后,我终于想出了解决问题的方法。所以如果有人有兴趣......刚刚改变了这部分代码

description = "Hello" & vbCrLf & "Today, I am going to describe my issue."    
csv.WriteLine summary & "," description & "," & "Consulting" & "," & reference_id 

desc1 = "Hello" 
desc2 = "Today, I am going to describe my issue."
csv.WriteLine summary & ",""" desc1 & vbCrLf & desc2 & """," & "Consulting" & "," & reference_id 

Ta Da ... 很有魅力...