Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Saving a JTable

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anybody tell me how i can save a JTable in a format that can be read easily by MS Excel?
thanks
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The CSV format is a simple format that is readable by Excel... it stands for Comma Seperated Values, and that's basically all it is... it's just text with each row on a separate line and each column separated by commas.
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do i have to save the file with a specific file extension other than .txt?
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm pretty sure if the file name ends in .csv excel will automatically recognize it. if not, open up excel and click on the menu Data > Get External Data > Import Text File. from there, follow the steps in the wizard for rules on how to import the data.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at poi?
Jakarta Poi
I had to do something similar to what you're asking. Poi has an excel table represented as a high level class (you can modify cells, rows etc. easily without worrying about the low-level event model). All I did was extend the HSSFWorbook class (it represents a workbook). You could make the extended workbook take a jtable as an argument, populate the first row with the column headings (or whatever), and the other rows with the row data. Or extend the sheet model and add the sheets to a programtically created or read workbook.
Check it out, I've found Poi extrodinarily useful in several circumstances.
Michael Crutcher
 
reply
    Bookmark Topic Watch Topic
  • New Topic