Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting multiline text in a csv field

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

like image 669
Tabrez Ahmed Avatar asked May 11 '12 07:05

Tabrez Ahmed


People also ask

How do I create a multiLine in CSV?

If you want to write multiple lines in csv file, you can try the sample below. string filePath = @"d:\test. csv"; String delim = ","; StringBuilder outString=new StringBuilder(); outString. Append("\""); //double quote outString.

Can CSV have multiple lines?

In order to process the CSV file with values in rows scattered across multiple lines, use option("multiLine",true) .

How many lines can CSV handle?

Cell Character Limits csv files have a limit of 32,767 characters per cell. Excel has a limit of 1,048,576 rows and 16,384 columns per sheet. CSV files can hold many more rows.

What is CSV quoting?

Quotation marks appear in CSV files as text qualifiers. This means, they function to wrap together text that should be kept as one value, versus what are distinct values that should be separated out.


2 Answers

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

enter image description here

like image 97
Grzegorz Grzybek Avatar answered Oct 25 '22 13:10

Grzegorz Grzybek


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)
like image 22
Peabody Avatar answered Oct 25 '22 14:10

Peabody