Discussion:
Exporting Jtable to CSV(Excel) with HEADER help needed
aloksharma2k27
2010-08-29 13:34:44 UTC
Permalink
hi here is my problem, i have successfully imported my jtable data to excel by writing a .csv file but now the problem is i can see any header info thus its all in-vain because whatever i do i cannot get header info to csv an the problem is i dont know much about csv files too....
areeda
2010-08-30 00:30:48 UTC
Permalink
Interesting question. How are you exporting your JTable data to a csv file?

I think what you want to do is to use JTable.getColumnModel() (See http://download-llnw.oracle.com/javase/1.5.0/docs/api/javax/swing/JTable.html) then iterate through the columns and get the Column Headers.

Writing out the column names as a row before the first data row will produce an Excel table that is close.

Joe
aloksharma2k27
2010-08-30 02:01:48 UTC
Permalink
k thanks for your reply so i just have to put the column names first, well that will work for now but i was thinking of some solution which can create a full formatted excel sheet.....but that will do.


Thanks.
Yves Hoppe
2010-08-30 10:12:16 UTC
Permalink
Hi,

i would suggest you use a csv framework for this case. Because csv also
needs to get encoded etc.. There are many java frameworks out there for
this.

In my experience SuperCSV (supercsv.sourceforge.net) is the simplest to
use. For real excel sheets, you could use Apache poi (
http://poi.apache.org/). CSV is just a "simple" format to exchange data
- for formatting etc. you have to use something other.

Yves
Post by aloksharma2k27
for your reply so i just have to put the column names first, well that will work for now but i was thinking of some solution which can create a full formatted excel sheet.....but that will do.
Loading...