Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Created Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of rows and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook())
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < RowNumbers; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

using (var table = sheet.RangeUsed().CreateTable())
{
table.Theme = XLTableTheme.TableStyleLight2;
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St

Viewing all articles
Browse latest Browse all 1877

Trending Articles