Closed
Description
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