aspose file tools*
The moose likes Java in General and the fly likes Multi line in csv file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multi line in csv file using java" Watch "Multi line in csv file using java" New topic
Author

Multi line in csv file using java

Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jan 02, 2012
Posts: 33
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Oct 13, 2005
Posts: 38334
    
  23
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Multi line in csv file using java