20

I want to insert a multiline text data in a CSV field.

Ex:

var data = "\nanything\nin\nthis\nfield";
var fields = "\"Datafield1\",\"Datafield2:"+data+"\"\n";

When I save fields into a csv file and open it using MS Excel, I get to see only the first column. But when I open the file using a text editor I see:

"Datafield1","Datafield2:
anything
in
this
field"

I don't know whether I am going against CSV standards. Even if I am going against Please help me with a workaround.

Thanks...

Tabrez Ahmed
  • 2,830
  • 6
  • 31
  • 48

2 Answers2

10

By default MS Excel uses semicolon as a separator. use ; and you'll see this:

enter image description here

Grzegorz Grzybek
  • 6,152
  • 3
  • 29
  • 42
  • Just use: `var fields = "\"Datafield1\";\"Datafield2:"+data+"\"\n";` – Grzegorz Grzybek May 11 '12 at 07:14
  • It's not working for me.. I tried manually in excel as ="'1';'1';'1'" and ="1;1;1".. Both are not working. Please help – Jay Shukla Jun 18 '15 at 11:15
  • The RFC 4180 CSV standard defines the structure of a how a big blob of string that spans many lines, is to be created. However one important gotcha is that when the next line begins with a whitespace character, many parsers consider it a different record. – Asad Hasan Oct 12 '19 at 13:19
4

Here I place some text followed by the NewLine char followed by some more text and the whole string MUST be quoted into a field in a csv file.

Do not use a CR since EXCEL will place it in the next cell.

""2" + NL + "DATE""

When you invoke EXCEL, you will see this. You may have to auto size the height to see the entire cell.

2

DATE

Here's the code in Basic

CHR$(34,"2", 10,"DATE", 34)
pinckerman
  • 4,115
  • 6
  • 33
  • 42
Peabody
  • 71
  • 1