how to import datas from excel to jTable?

user3670278 picture user3670278 · Jul 2, 2015 · Viewed 15.4k times · Source
JFileChooser fc = new JFileChooser();
    int option = fc.showSaveDialog(NewJFrame1.this);
    if(option == JFileChooser.APPROVE_OPTION){
        String filename = fc.getSelectedFile().getName();
        String path = fc.getSelectedFile().getParentFile().getPath();

        int len = filename.length();
        String ext = "";
        String file = "";

        if(len > 4){
            ext = filename.substring(len-4, len);
        }

        if(ext.equals(".xls")){
            file = path + "\\" + filename; 
        }else{
            file = path + "\\" + filename + ".xls"; 
        }
        toExcel(jTable1, new File(file));


    }

this is how i save my table to excel it works fine but i want to import these datas after i restart my program can someone help me about this ?

Answer

Gabriel Câmara picture Gabriel Câmara · Jul 2, 2015

You can use Apache POI to export your JTable Data.

See how to do it here, in this thread: apache poi: saving jtable to a file

Edit

I didn't read your question, if you're trying to IMPORT data, try these methods: http://www.zfqjava.com/article/How-to-import-excel-into-JTabel.html