Export Data to Excel Sheet
import java.io.*;
import javax.swing.*;
import javax.swing.table.TableModel;
/**
*
* @author NAVJYOTI
*/
public class ExcelExporter {
ExcelExporter(){}
public void export(JTable table,File file)throws Exception
{
TableModel tm=table.getModel();
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
for(int i=0;i<tm.getColumnCount();i++)
{
bw.write(tm.getColumnName(i)+"\t");
}
bw.write("\n");
for(int i=0;i<tm.getColumnCount();i++)
{
for(int j=0;j<tm.getColumnCount();j++)
{
bw.write(tm.getValueAt(i, j).toString()+"\t");
}
bw.write("\n");
}
bw.close();
}
}