EPPlus
EPPlus copied to clipboard
Using a template file results in a corrupted file
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(); }
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
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.
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.
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:
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.
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
Want it!