JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET
3.76k stars 1.17k forks source link

OutOfMemoryException: Array dimensions exceeded supported range exception occurs when formatting large amount of cells #203

Open Adbmnk opened 6 years ago

Adbmnk commented 6 years ago

I get the following Exception when I format a large set of columns: System.OutOfMemoryException: 'Array dimensions exceeded supported range.' _at System.Collections.Generic.List.setCapacity(Int32 value) at System.Collections.Generic.List.EnsureCapacity(Int32 min) at System.Collections.Generic.List.Add(T item) at CellStore.AddCell(ColumnIndex columnIndex, Int32 pagePos, Int32 pos, Int16 ix, T value) at CellStore.SetRangeValueSpecial(Int32 fromRow, Int32 fromColumn, Int32 toRow, Int32 toColumn, SetRangeValueDelegate Updater, Object Value) at OfficeOpenXml.ExcelStyles.SetStyleAddress(StyleBase sender, StyleChangeEventArgs e, ExcelAddressBase address, ExcelWorksheet ws, Dictionary`2& styleCashe) at OfficeOpenXml.ExcelStyles.PropertyChange(StyleBase sender, StyleChangeEventArgs e)

The code looks something like this. The Exception occurs when i>68.

for (i=0; i<120; i++)
{
     format = GetFormat(i);
     worksheet.Cells[2, i, 950000, i].Style.Numberformat.Format = format;
}
vaspervnp commented 5 years ago

I have the same problem. It is either caused during loading a large datatable (over 100000 rows and 180cols) or saving this as an excel file.