This project has moved. For the latest updates, please go here.

Load and save without change gives error message when opening in Excel.

Oct 10, 2013 at 1:06 PM
I load and save an xlsx file.
    var e1 = new FileInfo(@"C:\temp\mynewfile.xlsx");       
var pck1 = new ExcelPackage(e1);
var e3 = new FileInfo(@"c:\temp\tmpout.xlsx");
pck1.SaveAs(e3);
Process.Start(@"c:\temp\tmpout.xlsx");
The output file opens in Excel with an error message "Excel found unreadable content in 'tmpout.xlsx'. Do you want to recover the contents of this workbook?"

Clicking "yes" opens up Excel with "tmpout.xlsx [repaired]". Excel informs me that it was able to open it by removing content. Opening the logfile reveals this :

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error075840_01.xml</logFileName><summary>Errors were detected in file 'C:\temp\tmpout.xlsx'</summary>-<removedRecords summary="Following is a list of removed records:"><removedRecord>Removed Records: Named range from /xl/workbook.xml part (Workbook)</removedRecord></removedRecords></recoveryLog>

Searching the internet, I found that this could be due to Pivot tables. Inspecting using Excel, I did find some in the document (in other tabs), and deleted the Worksheets where there were pivot tables.
No change. Repeating the process leaves the same result.

My users are using a third party xlsx viewer which crashes when opening these documents.

Does anybody know what is going on? Did I miss any pivot tables? Should I do more than deleting the respective sheets? Is there any workaround? Can I remove the corrupt elements through the epplus API before saving?