i have a code that goes something like this:
public class excelwriter {
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("sheet1");
for (int o = 1; o < 1000000; o++) {
Row row = sheet.createRow(o);
for (int i = 0; i < 100000; i++) {
Cell cell = row.createCell(i);
}
}
try (FileOutputStream outputStream = new FileOutputStream("C:/JavaBooks.xlsx")) {
workbook.write(outputStream);
}
}
}
My problem is the heapspace error, to which i get sooner or later using this code, as the workbook object stores all the cells. How can i modify the code, that java after writing a row with all the cells, writes it to xlsx and throws the data away (or after 1000 rows if that makes it faster). Thank you