Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Writing 100,000-row Excel files in .NET with 27 MB allocated

Description and use

SheetStream streams 100,000‑row Excel exports with only 27 MB memory and 534 ms, outperforming other .NET libraries that consume hundreds of megabytes.

Problem

Most .NET Excel libraries build the whole workbook in memory, causing hundreds of megabytes to gigabytes of allocation for a 100,000‑row export.

Outcome

SheetStream writes 100,000 rows × 10 formatted columns in 534 ms using only 27 MB of memory, compared to 343 MB–1 104 MB for other libraries.

Workflow

  • 1. Create a ZipArchive entry for "xl/worksheets/sheet1.xml". 2. Stream XML via XmlWriter into the entry. 3. Write layout elements (cols, frozen panes) before data. 4. Collect post‑sheetData features (merged cells, conditional formatting, etc.) while writing rows. 5. Emit collected features in schema order when sealing the sheet. 6. Write sharedStrings.xml and styles.xml after all sheets, keeping only small in‑memory dictionaries. 7. For AutoFit, spill rows to a temp file, measure widths, write header, then copy rows back in 64 KB chunks. 8. For template filling, stream template XML, adjust style and string numbering, stretch tables, drop calcChain.xml, and let Excel recalc on open.

Evidence

Most .NET Excel libraries build the whole workbook in memory and save it at the end. That's convenient, and it's why a 100,000-row export can allocate hundreds of megabytes to over a gigabyte.

Source

100,000 rows × 10 formatted columns, BenchmarkDotNet, .NET 8: SheetStream (fastest compression) 534 ms 27 MB; MiniExcel 596 ms 343 MB; EPPlus 4.5.3.3 2,287 ms 390 MB; ClosedXML 3,103 ms 1,104 MB.

Source

SheetStream throws a clear exception if you set them late.

Source

  • Record date: 2026-10-14T11:40:57.748Z