title: How to create a method to fill up an excel table
body: <p>I am trying to create a method to fill up an excel table if it is filled up or not, but I dont know how can I implement the code when the excel table is filled up. Can someone help me, please? Here is the code:</p>
  
  <p>Iam using API JXL</p>
  
  <pre><code>public void fillData(JTable table, File file) {
  
      try {
  
          boolean controladorExcel = false; //Excel controler, if is filled up or not
  
          Workbook workbookPreenchido = Workbook.getWorkbook(new File(file.getName())); //workbook is filled up
  
          Sheet sheet = workbookPreenchido.getSheet(0); 
  
              Cell a1 = sheet.getCell(0, 0);
  
              String as1 = a1.getContents();
  
              if(as1 == null){
                  controladorExcel = true; //Excel table is blank
              }else{
                  controladorExcel = false; //Excel table is filled up
              }
  
  
          workbookPreenchido.close();
  
          if (controladorExcel == true) { //If the excel table is blank
              WritableWorkbook workbookVazio = Workbook.createWorkbook(file); //workbook is blank
  
  
              WritableSheet sheet1 = workbookVazio.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);
                  }
              }
              workbookVazio.write();
              workbookVazio.close();
  
          }else{ //If the excel table is filled up
  
          }          
  
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>