Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Export records from JTable to Excel_Java

public void toExcel(JTable table, File file){
    try{
        TableModel model = table.getModel();
        FileWriter excel = new FileWriter(file);

        for(int i = 0; i < model.getColumnCount(); i++){
            excel.write(model.getColumnName(i) + "	");
        }

        excel.write("
");

        for(int i=0; i< model.getRowCount(); i++) {
            for(int j=0; j < model.getColumnCount(); j++) {
                excel.write(model.getValueAt(i,j).toString()+"	");
            }
            excel.write("
");
        }

        excel.close();

    }catch(IOException e){ System.out.println(e); }
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Export #records #JTable
ADD COMMENT
Topic
Name
7+2 =