Skip to content

Bug with Open XML SDK v3.0.2 - Exception in AddWorkbookPart Method #1745

Closed
@bhargavgaglani07

Description

@bhargavgaglani07

Describe the bug
With v3.0.2 AddWorkbookPart method is throwing exception - The specified package is invalid. The main part is missing.

Refer attached file (EmptyExcel.xlsx) to be used with below sample code.

using (SpreadsheetDocument document = SpreadsheetDocument.Open($"EmptyExcel.xlsx", true))
 {
     if (document.WorkbookPart != null)
     {
         document.DeletePart(document.WorkbookPart);
     }

     /*** below line throws error ***/
     var workbookPart = document.AddWorkbookPart();
     workbookPart.Workbook.Save();
 }

Observed behavior
Exception - The specified package is invalid. The main part is missing. Kindly note that same is working with v2.20.0.

Expected behavior
It should add workbook part instead of throwing exception.

Desktop (please complete the following information):

  • OS: Windows
  • Office version: e.g. 16.0.17531.20190
  • .NET Target: .NET Framework 4.8
  • DocumentFormat.OpenXml Version: 3.0.2

Debug Info
Adding below line post delete part call resolves issue

document.ChangeDocumentType(SpreadsheetDocumentType.Workbook);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions