ClosedXML / ClosedXML/ClosedXML
Asp Net Core 3.1 Large Data Export Excel with ClosedXML
- Dominant language
- C#
- Stars
- 5.7k
- Forks
- 933
- Avg merge
- 12h 14m
- Merged PRs (30d)
- 1
Description
## Read and complete the full issue template
**Do you want to request a *feature* or report a *bug*?**
- [ ] Bug
- [ ] Feature
- [x] Question
**Did you test against the latest CI build?**
- [x] Yes
- [ ] No
**Version of ClosedXML**
0.95.3
I need to get 400-500k data in excel output, but in the Worksheet.SaveAs (stream) part, the data takes up 6gb of ram at a time and the application closes when the ram is not enough on the computer. What I want is to get excel output, but even if it cannot do this, I want to at least prevent the application from closing. What should I do for this?
sample excel data:

this is the sample code (I can't show it because some parts are private)
string fileName = "ex-" + Guid.NewGuid() + ".xlsx";
string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/TempFiles/" + fileName);
using (var workbook = new XLWorkbook(XLEventTracking.Disabled))
{
DataTable dt = new DataTable("exportData");
#region Headers
// I am filling the headers of the table
#endregion
#region Rows
// I am filling the rows of the table
#endregion
workbook.Worksheets.Add(dt);
using (var stream = new FileStream(fullPath, FileMode.Create))
{
workbook.SaveAs(stream, false);//the problem is in the saveas command, ram is suddenly increasing
stream.Close();
stream.Dispose();
workbook.Dispose();
dt.Clear();
dt.Dispose();
responseJson = null;
responseContent = null;
GC.Collect();
}
}
error

Contributor guide
Research direction
Start at workbook.SaveAs(stream, false) in the supplied sample and reproduce the memory increase with the 400–500k-row DataTable export. Compare the observed behavior with the reported ClosedXML 0.95.3 version and determine whether the issue identifies a library defect or requires a documented usage limitation; the issue is complete when that behavior and next step are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100