0

I am trying to produce a large excel (~10 MB) with multiple sheets (5). The current implementation was using XSSFWorkbook but now we are running into OutOfMemoryError in the deployed environment so made the switch to use SXSSFWorkbook. The constructor takes in a window size as an argument. I tried with the default size but ran into this error:

java.lang.IllegalArgumentException: Attempting to write a row[4] in the range [0,8] that is already written to disk.
at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:125)
at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:61)
at org.apache.poi.ss.util.CellUtil.getRow(CellUtil.java:126)
at org.apache.poi.ss.util.RegionUtil.setBorderLeft(RegionUtil.java:75)

Updating the window size to 500 seems to have 'fixed' the issue but I am still wondering if that is the ideal solution for this problem or should I be doing something else?

SXSSFWorkbook workbook = new SXSSFWorkbook(null, 500);

I saw the answers here but still wasn't clear. I am using JDK 11, poi-ooxml 5.2.2 and am running on a Mac.

linuxNoob
  • 600
  • 2
  • 14
  • 30
  • Bigger window size means more memory is required, but allows you to change your mind over a wider range of rows – Gagravarr Aug 31 '23 at 13:55
  • @Gagravarr but what would be the ideal value for it? I'm wondering if allowing the developer to configure it is a good enough solution or if there are better ways to solve it. I don't have visibility from a future data standpoint – linuxNoob Aug 31 '23 at 14:33
  • There is no ideal for everyone, it depends on how much memory you want to use, and how far back you need to modify rows – Gagravarr Aug 31 '23 at 16:31

0 Answers0