Inserting multiline text in a csv field
Asked Answered
H

2

22

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...

Hewlett answered 11/5, 2012 at 7:5 Comment(0)
K
10

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

enter image description here

Krissykrista answered 11/5, 2012 at 7:9 Comment(3)
Just use: var fields = "\"Datafield1\";\"Datafield2:"+data+"\"\n";Krissykrista
It's not working for me.. I tried manually in excel as ="'1';'1';'1'" and ="1;1;1".. Both are not working. Please helpArgonaut
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.Tessellated
P
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)
Penetralia answered 15/9, 2013 at 19:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.