I need to save data into an Excel file(.xlsx). I decided to use "ClosedXML" NuGet (v0.95.3) (https://www.nuget.org/packages/ClosedXML/) for implementing it, after getting several recommendations on this NuGet from different developers.
Recently I encounter a problem when exporting 50k rows:
I'm saving the data into a given stream using the "SaveAs()" method, and I already used the "XLEventTracking.Disabled" optimization.
Probably, I'm not the first one which dealing with Excel files, so:
Thanks in advance!
I have used ClosedXML
for a few years, and I have to admit that the library - as of version 0.95.1
- is pretty much unusable for larger Excel reports. The memory usage/footprint is a disaster. A really large report can easily allocate several gigabytes of RAM.
The performance problems you have seen are linked to GC
(garbage collection). Looking at the code, you quickly realize that fixing this will require several iterations of improvements.
I would recommend looking at other libraries. Personally, I prefer to use the native libxlsxwriter library. You can easily integrate with it, using DllImport interop. For large reports, consider the Constant Memory mode. With constant memory, it outperforms ClosedXML
in terms of both CPU and RAM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With