• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi line in csv file using java

 
Vincent Oh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone has any idea to write a csv file with multiple lines in a cell? what is the special character needed to go to the next line? i tried /r and /n already, but it will go into a new row instead of next line in a cell.

thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no standard way that I know of to have a single cell in a CSV file occupy multiple rows or columns. By definition, a CSV file has one data row per file line, and one data cell per element in that line. You'll have to define your own format, or use something like Apache POI to handle it as an Excel file. Excel can have a single cell span multiple columns or rows, but it does so in its own format, not simple CSV.
 
Vincent Oh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the way already.
http://en.wikipedia.org/wiki/Comma-separated_values

and it uses \r instead of \n. and the sentence that requires to break need to be in quotations.

for eg.

"This is a\rbreak line"
will give
"This is a
break line"

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vincent Oh wrote:I found the way already.
http://en.wikipedia.org/wiki/Comma-separated_values

and it uses /r instead of /n. and the sentence that requires to break need to be in quotations.

for eg.

"This is a\rbreak line"
will give
"This is a
break line"



That works in a system where you interpret \n as a line break and you don't interpret \r as a line break. As long as your parser interprets it that way, it will work.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Windows® they use \r\n as line breaks and on *nix (Unix, Linux, newer Macs, etc) they use \n alone. I think only old Macs used \r, but the whole thing looks like a flaky platform‑dependent solution to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic