Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bhargavgaglani07 opened this issue Jul 3, 2024 · 0 comments · Fixed by #1836
Closed

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

bhargavgaglani07 opened this issue Jul 3, 2024 · 0 comments · Fixed by #1836
Assignees

Comments

@bhargavgaglani07
Copy link

bhargavgaglani07 commented Jul 3, 2024

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants