Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How To Export Records From JTable To MS Excel

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); }
}
Comment

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); }
}
Comment

PREVIOUS NEXT
Code Example
Java :: public void bookingDetails(View view) { Intent intent = new Intent (PackageContext:this, MainActivity.class); intent.putExtra("name", value "kenny"); startActivity(intent); } 
Java :: darkhub 
Java :: what is resource bundle class in java 
Java :: Obtaining all data in a table with Hibernate 
Java :: menuitemcompat getactionview is deprecated in android 
Java :: java web.xml 
Java :: sorting boolean array with prime index 
Java :: Sample NavigableMap 
Java :: masquer saisie mot de passe java console 
Java :: java casting method 
Java :: also in java 
Java :: java tester si un caractere est une lettre 
Java :: selenium treeview java 
Java :: {1 2 3 4 5 } 
Java :: how to disable the auto-configuration? 
Java :: fix intellij resetting the java version everytime you add a dependency 
Java :: compile time exception in java 
Java :: move the zero elementts in array in java in tutorialspoint.dev 
Java :: how to load template file from resource folder in spring boot project 
Java :: android studio clear child views 
Java :: setsystemuivisibility example 
Java :: java feld erstellen 
Java :: javafx treeview directory 
Java :: how to uncomment a block of statements in java 
Java :: java :: operator 
Java :: varargs java 
Java :: java.lang.stringindexoutofboundsexception: string index out of range: 10 
Java :: constructeur java 
Java :: java float precision 
Java :: android get id of view 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =