1

I use DotNetCore.NPOI to export data into *.xlsx file and my program seems to be running out of memory, so I tried to utilize the relatively new SXSSFWorkbook to lower the memory footprint, but the resulting file is always corrupted and can not be opened.

Even this simple sample (originally in Java or something) creates a corrupted file:

var wb = new SXSSFWorkbook(new XSSFWorkbook(), 1024); // keep 1024 rows in memory
var sh = wb.CreateSheet();
// Should not even have to flush anything before end, only 100 lines
for (int rownum = 0; rownum < 100; rownum++)
{
    var row = sh.CreateRow(rownum);
    for (int cellnum = 0; cellnum < 10; cellnum++)
    {
        var cell = row.CreateCell(cellnum);
        cell.SetCellValue($"{rownum}:{cellnum}");
    }
}
var o = new FileStream("test.xlsx", FileMode.Create, FileAccess.Write);
wb.Write(o);
o.Close();
wb.Dispose();

When I change the first line to this, it works (but always keeps entire document in memory):

var wb = new XSSFWorkbook();
...

Not sure if I should pass XSSFWorkbook instance into SXSSFWorkbook instance like this: new SXSSFWorkbook(new XSSFWorkbook(), 1024), but don't know what else to do. SXSSFWorkbook constructor in the original sample only required the number of rows. Can not find any sample for .NET specifically.

Thanks for any help.

Kabuto5CZ
  • 303
  • 2
  • 10

2 Answers2

0

Dotnetcore.NPOI is NOT official NPOI release and they stop maintaining this branch for a long time. Please use https://www.nuget.org/packages/NPOI/ instead. If it's confirmed as a bug, please submit issues to https://github.com/tonyqus/npoi/issues

Tony Qu
  • 676
  • 8
  • 14
0

As of now it IS official release: https://www.nuget.org/packages/DotNetCore.NPOI

zzhelev
  • 1
  • 1