How to use NPOI SXSSFWorkbook to export large xlsx

0

I have to export to a client in Excel 2007 (xlsx) a BBDD table of 500,000+ records through web access. Using NPOI or Epplus everything works fine until the table is very large and an Out of Memory is obtained. (ASP.NET-C # -VS2015)

The latest version of NPOI (3.20) indicates that you add Streaming to be able to export to XLSX. I am using therefore SXSSFWorkbook , I create the sheet, fill all the rows creating the cells and filling them correctly ... but when sending the client the file, it occupies little and only contains Row 0, the header. Records are not exported with the contents of the table.

If I change SXSSFWorkbook for the non-stream type ( XSSFWorkbook ), the same code works perfectly (limiting the table to about 20,000 records).

Does NPOI really support streaming? Has someone made it work?

Edit: To make the export to the client I have tried several ways:

using (var outStream= new MemoryStream())
{ 
   Response.Clear();                
   workbook.Write(outStream);

   Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

   Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "ExportTest.xlsx"));                   

   Response.BinaryWrite(outStream.ToArray()); 
   Response.End();       
}

I have also tried to create a FileStream to write the workbook created to save it directly on disk ... the same result, in both cases only export row 0.

All the rows are generated in the same way.

    
asked by SonhanDev 30.10.2017 в 14:32
source

0 answers