This project has moved and is read-only. For the latest updates, please go here.

Corrupt XLS documents when saving based on a template

Mar 14, 2012 at 9:31 AM
Edited Mar 14, 2012 at 9:33 AM

I have a series of XLS documents that I converted to XLSX using Mac Excel 2008.  These files serve as the templates, and open just fine in mac excel, and on windows.  

When I use EPPlus to save a new excel file, using one of these as the template, the resulting files are the correct size but are reported as corrupt by win/mac excel.

These files have Unicode characters in them (chinese), as well as english, if that is of any significance.  They don't have any formulas, and are basically just formatting templates. 


var fileOut = new FileInfo(outFileName);
var fileTemplate = new FileInfo(xlsxTemplatePath);

using (var package = new ExcelPackage(fileOut, fileTemplate)) {
    var wbk = package.Workbook;
    var sheet = wbk.Worksheets[1];
    // all code that modifies the sheet has been commented out
    // which should result in a duplicate of the original

Any ideas on how to go about this?  In the end I want to just stream the output to the browser as a download without actually saving it, but only after I get this to work :)  It doesn't seem to hard, just .GetAsByteArray() and send.

Thanks for any help

Mar 14, 2012 at 9:46 AM

Well... I think I found the culprit.  MAC EXCEL (2008)!

I had a colleague save them using Excel 2010 on Windows, and the end result from those is just fine.  Damn.  So much time wasted.

If you want a sample of the docs that come out corrupt, I can send one over.  Maybe it's a bug, maybe not.