-
Notifications
You must be signed in to change notification settings - Fork 547
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
After AddWorkbookPart() I recieved "Cannot retrieve parts of writeonly container" Exception from System.IO.Packaging #1809
Comments
Hi @Reules, can you share the code that causes this error? Thanks! |
Hi @Reules, I am using v3.1.1 and the following code with using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
string xlsx = @"C:\some\dir\AddWorkbookPart.xlsx";
// Create a workbook document by supplying the file path.
// By default, AutoSave = true, Editable = true, and Type = xlsx.
using (var spreadsheetDocument = SpreadsheetDocument.Create(xlsx, SpreadsheetDocumentType.Workbook))
{
// Add a WorkbookPart to the document.
WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Add Sheets to the workbook.
Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
// Append a new worksheet and associate it with the workbook.
Sheet sheet = new Sheet()
{
Id = spreadsheetDocument?.WorkbookPart?.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "MyNewSheet"
};
sheets.Append(sheet);
} |
Hi @Reules, Are you somehow opening the file as write only? |
Hi @mikeebowen Thanks for the reply, yes, before the AddWorkbookPart, i used |
In System.IO.Packaging.Package, the Since what you're seeing is the expected behavior, I will close this as by design. |
Describe the bug
Recently I updated OpenXML from 2.18.0 to 3.1.0.
The function AddWorkbookPart() didn't work anymore.
Always get the System.IO.IOException "Cannot retrieve parts of writeonly container".
Screenshots
Anyone knows the problem?
The text was updated successfully, but these errors were encountered: