Low memory writing/reading with Apache POI

后端 未结 2 948
野的像风
野的像风 2021-01-06 07:16

I\'m trying to write a pretty large XLSX file (4M+ cells) and I\'m having some memory issues.

I can\'t use SXSSF since I also need to read the existing cells in the

2条回答
  •  再見小時候
    2021-01-06 08:09

    To handle large data with low memory, the best and I think the only option is SXSSF api-s. If you need to read some data of the existing cells, I assume you do not need the entire 4M+ at the same time. In such a case based on your application requirement, you can handle the window size yourself and keep in memory only the amount of data you need at a particular time. You can start by looking at the example at : http://poi.apache.org/spreadsheet/how-to.html#sxssf

    Something as

    SXSSFWorkbook wb = new SXSSFWorkbook(-1); // turn off auto-flushing and accumulate all rows in memory
    // manually control how rows are flushed to disk 
    if(rownum % NOR == 0) {
    ((SXSSFSheet)sh).flushRows(NOR); // retain NOR last rows and flush all others
    

    Hope this helps.

提交回复
热议问题