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?
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.
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.
To write multiple rows to a CSV file at once, you use the writerows() method of the CSV writer object.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With