EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

xlsx file size is inflated with every Save()

Open SergiyStoyan opened this issue 3 years ago • 1 comments

Hi,

When an xlsx has hyperlinks in the sheet, the file size is growing unrestrictedly with every Save(). How to reproduce:

1)create an empty xlsx:

var package = new ExcelPackage(new FileInfo(file));
worksheet = package.Workbook.Worksheets.Add(name);
package.Save();

2)open the file in LibreOffice Calc and add hyperlinks to some cells. Alternatively, they can be created by the code:

var package = new ExcelPackage(new FileInfo(file));
var worksheet = package.Workbook.Worksheets[1]; 
for (int i = 1; i <= 10; i++)
{
	worksheet.Cells[1, i].Hyperlink = uri;
	worksheet.Cells[1, i].Value = value;
}
package.Save();

So, the way of creating hyperlinks does not matter.

3)now, run this:

var package = new ExcelPackage(new FileInfo(file));
var worksheet = package.Workbook.Worksheets[1]; 
for (int i = 1; i <= 10; i++)
	package.Save();

and you'll see that each time you run it, the file size is growing. File comparison reveals that some management info like styling or so is inflating. If the file is open and saved by LibreOffice Calc, its size comes back to normal again.

This issue is experienced with the later 4.. and 5.4.0 Epplus versions. In practice I got a file of 40kB inflated to 80Mb because of many Save() called on it. Is there a way to fix it? Thank you!

SergiyStoyan avatar Nov 05 '20 10:11 SergiyStoyan

Yes, EPPlus leaves the worksheets external releations (hyperlinks) and create new upon save. I'll try to provide a fix for the next version.

JanKallman avatar Nov 09 '20 12:11 JanKallman

Hi again, I missed to update this issue. This issue should be fixed in the latest version of EPPlus.

JanKallman avatar Dec 02 '22 06:12 JanKallman