KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to write a result set of more than 65000 rows in xlsx file. So, I am trying to use Apache POI 3.7. I get an OutOfMemoryError: Java heap space. How do I solve this problem besides increasing JVM memory which doesn't seem to solve the problem. Simple sample code: public static void main(String[] args) throws IOException { Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. for (int i=0;i<65000;i++){ Row row = sheet.createRow((int) i); // Create a cell and put a value in it. Cell cell = row.createCell(0); cell.setCellValue(1); // Or do it on one line. row.createCell(1).setCellValue(1.2); row.createCell(2).setCellValue( createHelper.createRichTextString("This is a string")); row.createCell(3).setCellValue(true); } // Write the output to a file FileOutputStream fileOut = new FileOutputStream("test1.xls"); fileOut.flush(); wb.write(fileOut); fileOut.close(); }
Tags (comma-separated)
Save Edits
Cancel