NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Exporting Jtable to CSV(Excel) with HEADER help needed

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
aloksharma2k27



Joined: 19 Jul 2010
Posts: 4

PostPosted: Sun Aug 29, 2010 1:34 pm    Post subject: Exporting Jtable to CSV(Excel) with HEADER help needed Reply with quote

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 cant see any cell header(or any info like column name as in JTable) 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....
Back to top
areeda



Joined: 28 Aug 2008
Posts: 484
Location: Los Angeles

PostPosted: Mon Aug 30, 2010 12:30 am    Post subject: Reply with quote

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
Back to top
aloksharma2k27



Joined: 19 Jul 2010
Posts: 4

PostPosted: Mon Aug 30, 2010 2:01 am    Post subject: Reply with quote

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.
Back to top
yhoppe



Joined: 16 Aug 2010
Posts: 3

PostPosted: Mon Aug 30, 2010 10:15 am    Post subject: Exporting Jtable to CSV(Excel) with HEADER help needed Reply with quote

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



On 30.08.2010 04:01, aloksharma2k27 wrote:
Quote:
Quote:
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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo