JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.Net Core 3.0: use of foreach loop causes Excel file to balloon

MightyFerengi opened this issue · comments

While using EPPlus 4.3 or 5.0 to build an Excel file in .Net Core 3.0, I have found that use of a foreach loop to create and populate worksheet causes massive amounts of unseen data to be added to the file and takes several minutes to save or convert to byte array. I have used the code listed in the attached file EPPlus Original which creates a file over 320MB in size and takes several minutes to convert to byte array.

EPPlus Original.txt

When I replaced that code with the code listed in EPPlus Rework, the Excel file is now slightly under 17MB and takes less than a minute to convert to byte array.

EPPlus Rework.txt

I'm now rebuilding the same code without any foreach loops to see if the extra unseen data is built due to the loop itself or if it is only the foreach loop. Either way, this seems like an important performance bug.

Many thanks, we will look into this asap. I have created an issue in our EPPlus 5 repo that links to this EPPlusSoftware/EPPlus#33

The problem is this row…
worksheet4.SelectedRange["b7:i"].Style.Numberformat.Format = "\\$###,###,##0.00";
This is not a valid address
EPPlus interpreters it as b7:i1048576, which will generate a styleid for every cell in the range.
I'll add a validation fix for it in version 5.