title: Import data from JTable to Excel
body: <p>i have code to import data from JTable to Excel like this:</p>
  
  <pre><code>public void toExcel(JTable table, File file){
  try {
  
          WritableWorkbook workbook1 = Workbook.createWorkbook(file);
          WritableSheet sheet1 = workbook1.createSheet("First Sheet", 0); 
          TableModel model = table.getModel();
  
          for (int i = 0; i &lt; model.getColumnCount(); i++) {
              Label column = new Label(i, 0, model.getColumnName(i));
              sheet1.addCell(column);
          }
          int j = 0;
          for (int i = 0; i &lt; model.getRowCount(); i++) {
              for (j = 0; j &lt; model.getColumnCount(); j++) {
                  Label row = new Label(j, i + 1, 
                          model.getValueAt(i, j).toString());
                  sheet1.addCell(row);
              }
          }
          workbook1.write();
          workbook1.close();
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  
  
  void excell(){
            toExcel(TabelPerencanaan, new File("H:\\Hasil.xlsx"));
                  JOptionPane.showMessageDialog(null, "Data saved at " +
                          "'H: \\ Hasil.xlsx' successfully", "Message",
                          JOptionPane.INFORMATION_MESSAGE);
  </code></pre>
  
  <p>}</p>
  
  <p>But, when open file "Hasil.xlsx" always error. so, that file can't opened. i don't know why like that. thanks</p>