EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Using a template file results in a corrupted file

Open jpabdilla-gfi opened this issue 6 years ago • 6 comments

Using version 4.0.3 I used to use a template excel file and reproduce a new file. Since I updated to version >4.1.0 or higher, the output file is resulting in a corrupted file.

using (ExcelPackage package = new ExcelPackage(templateFile)) { bytes = package.GetAsByteArray(); }

jpabdilla-gfi avatar Oct 25 '17 11:10 jpabdilla-gfi

Same problem. Opening file with LibreOffice, WPSOffice doesn't reproduce error, but Excel finds some corrupted data, then recovers file (successfully). I work with EPPlus 4.1.1.0 Ver. 4.0.5 works filne

hunty avatar Dec 04 '17 09:12 hunty

Same problem for us. We are doing the same template Excel file approach to generate new files. Also tried simply taking a good Excel file, doing no updates, and just getting the byte array. Both approaches result in the same error message about a corrupted file when using version 4.1.1. We downgraded to version 4.0.5 and everything worked fine.

DSchueck avatar Dec 22 '17 20:12 DSchueck

Downgrading to 4.0.5 didn't solve problem for us. I can reproduce this on 4.0.3, 4.0.5, 4.1.1 and even 4.5.0.2-rc.

To work around this bug we need to save the package into stream and then get the byte array out of it ourselves.

michalpenka avatar Mar 01 '18 14:03 michalpenka

Don't know if it's the same problem that you guys have but i was using Epplus 4.1.0 and my problem didn't get solved by downgrading. Only tested until version 4.0.5. I noticed that if i deleted some formulas in the original file, when exporting the file didn't get corrupted. I was duplicating rows and thought EPPlus was trying to copy some formulas in those rows, and for some reason the formulas were corrupted. What i have found is that if i have merged cells, if those cells have formulas, the file gets corrupted. My example: image

When i deleted the bottom formula, and merged the cells again, i could duplicate and export the file in Epplus and the file didn't get corrupted!! It solved my problem.

radikale avatar Mar 16 '18 11:03 radikale

I believe some of these problems were cause by two independent changes in the code since 4.0.5. Specifically, if you have named "column" ranges of the style "$A:$C" (or just "A:C"), and called InsertRows, then that would result in a corrupt workbook. Similarly, if you have named "row" ranges and inserted columns the corruption would occur.

I've created a pull request to fix the issue: https://github.com/JanKallman/EPPlus/pull/289

lieszkol avatar Aug 14 '18 13:08 lieszkol

Want it!

nsemikov avatar Nov 20 '19 14:11 nsemikov