Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Exporting code is wrong...

  Asked By: Koko    Date: Aug 31    Category: Java    Views: 420
  

Hi,
Am a new comer on this forum and I need your help please!

I want to export to Excel a JTable datas. This is the code:

public class JExporter {
public void exporter(JTable table, File file)
{
try
{
TableModel model = table.getModel();
FileWriter out = new FileWriter(file);

for(int i=0; i < model.getColumnCount(); i++) {
out.write(model.getColumnName(i) +"\t");
}
out.write("\n");

for(int i=0; i< model.getRowCount(); i++) {
for(int j=0; j<model.getColumnCount(); j++) {
Object value=model.getValueAt(i,j);
if ( value!=null ){
out.write(value.toString()+"\t");
}
else
{
out.write(" ");
}
out.write("\n");
}
}
out.close();
} catch(Exception err){
err.printStackTrace();

}
}

}

But when I try to export data, it fall into a single columm. please help me to export my datas solving this for me

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Exporting code is wrong... Or get search suggestion and latest updates.




Tagged: