title: OutofMemoryError:Java heap space when writing large no. of rows to xls file
body: <p>I need to write a resultset of more than 1,000,000 rows in xls file(Microsoft 97-xp). So I am trying to use JExcel API But I get error OutOfMemoryError: Java heap space . How do I solve this problem besides increasing JVM memory or creating different excel files and then merge them manually. I don't even want to create CSV file. Please help.</p>
  
  <p>Sample Code:</p>
  
  <pre><code>int sheetNumber = 1;
  int maxSheetSize=65000;
  int start = 0;
  int end=maxSheetSize;
  int totalsize=1000000;
  int completed = 0;
  int columnCount=10;
  WritableWorkbook workbook = Workbook.createWorkbook(new File("output.xls"));
  
  while (completed &lt; totalsize) {
      WritableSheet sheet = workbook.createSheet("Sheet " + (sheetNumber++), 0);
      for (int r = start; r &lt; end; r++) {
          int i=1;
          for (int c = 0; c &lt; columnCount; c++) {
              Label label = new Label(c, i, "data from resultset");
              sheet.addCell(label);
          }
          i++;
      }
      completed += (end - completed);
      start = end;
      end = (totalsize - completed) &lt; maxSheetSize ? (totalsize - completed) : completed + maxSheetSize;
      end = end &lt; maxSheetSize ? totalsize : end;
  }
  workbook.write();
  workbook.close();
  </code></pre>