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

Problem saving with multi-sheet template

Jul 3, 2013 at 9:40 AM
Edited Jul 3, 2013 at 10:17 AM
Scenario: opening a template xlsx with multiple sheets on it, writing some values to first sheet, then calling SaveAs ( ... ). This worked just fine until I added those extra worksheets on the template.

Any ideas, apart from just not having multiple sheets on my template?

EDIT: Modifying the template over and over again, I managed to track whatever crashes saving the file into some styles/comments used in one of the extra worksheets. Pretty standard Excel stuff, but I guess there was something among them that doesn't sit well with OpenOfficeXml. While my problem has been evaded, I'll leave this thread here, just in case anyone gets same error or just wants to dig to the roots of the issue.
System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=Error saving file C:\....aco.xlsx
  Source=EPPlus
  StackTrace:
    at OfficeOpenXml.ExcelPackage.Save()
    at OfficeOpenXml.ExcelPackage.SaveAs(FileInfo file)
    ...

InnerException: System.InvalidOperationException
   HResult=-2146233079
   Message=Cannot add part for the specified URI because it is already in the package.
   Source=WindowsBase
   StackTrace:
        at System.IO.Packaging.Package.CreatePart(Uri partUri, String contentType, CompressionOption compressionOption)
        at OfficeOpenXml.ExcelWorksheet.SaveComments()
        at OfficeOpenXml.ExcelWorksheet.Save()
        at OfficeOpenXml.ExcelWorkbook.Save()
        at OfficeOpenXml.ExcelPackage.Save()
   InnerException: