• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving a JTable

 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • 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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Do i have to save the file with a specific file extension other than .txt?
 
Jon Dornback
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • 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.
 
Michael Crutcher
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!