Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write data on multiple lines BUT within the same cell of csv?

Tags:

I want to create one csv file using C#.

I have some data which I want to write on multiple lines BUT within the same cell.

For example If I have following three sentences,

Sample sentence 1. This is second sample sentence. and this is third sentence. 

I want to write all these three sentences within single cell of csv file but I want three of them on separate line.

My expected output is :

Sample sentence 1. This is second sample sentence. and this is third sentence. 

Currently I am trying to achieve this by using \n character between two sentences but when I do it this way, all three sentences go on separate row.

Can anyone please tell me how to solve this problem?

like image 536
Shekhar Avatar asked Jun 29 '11 05:06

Shekhar


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) . This yields below output. Note: By default, using the multiline option; Spark considers you have multiline rows in double-quotes or any special escape characters.

Is there any function to write multiple records in a CSV file at once?

To write multiple rows to a CSV file at once, you use the writerows() method of the CSV writer object.


1 Answers

To quote Wikipedia:

Fields with embedded line breaks must be enclosed within double-quote characters.

Like e.g.:

1997,Ford,E350,"Go get one now they are going fast" 
like image 78
Uwe Keim Avatar answered Sep 21 '22 18:09

Uwe Keim