• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multi line in csv file using java

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic