title: Inserting data from arraylist in chunks in excel file using apache poi
body: <p>I have the arraylist of data in the following format :</p>
  
  <p>ArrayList> listResultData. Now collection contains around 11k+ rows to be inserted in the excel.
  When i insert these 11490 rows in excel it took <strong>6 hrs to insert the records</strong>, that means its very bad performance issue. Is there anyway to insert the data in excel in chunks for 1000 rows at a time (<strong>means there should be something like executeBatch() in sql for inserting records</strong>). A row contains 4-5 columns also.</p>
  
  <p>Following is the code i have been using :</p>
  
  <pre><code>public boolean setArrayListData(String sheetName, ArrayList&lt;ArrayList&lt;String&gt;&gt; listResultData) {
      try {
          fis = new FileInputStream(path);
          workbook = new XSSFWorkbook(fis);
  
          int index = workbook.getSheetIndex(sheetName);
  
          if (index == -1)
              return false;
  
          sheet = workbook.getSheetAt(index);
  
          int colNum = 0;
          int rowNum = this.getRowCount(sheetName);
          rowNum++;
          for (ArrayList&lt;String&gt; al : listResultData) {   
              for (String s : al) {
                  sheet.autoSizeColumn(colNum);
                  row = sheet.getRow(rowNum - 1);
                  if (row == null)
                      row = sheet.createRow(rowNum - 1);
  
                  cell = row.getCell(colNum);
                  if (cell == null)
                      cell = row.createCell(colNum);
  
                  // cell style
                  // CellStyle cs = workbook.createCellStyle();
                  // cs.setWrapText(true);
                  // cell.setCellStyle(cs);
                  cell.setCellValue(s);
                  //System.out.print("Cell Value :: "+s);
                  colNum++;
              }
              rowNum++;
              colNum = 0;
              //System.out.println("");
          }
  
          fileOut = new FileOutputStream(path);
          workbook.write(fileOut);
          fileOut.close();
          workbook.close();
          fis.close();
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>Please suggest !!</p>