Reputation: 91
My OpenXML SDK-based application iterates through workbooks and inside that, through worksheets.
I would like to factor out the retrieval of the worksheet.
Given a Spreadsheet.Worksheet
, how do I find its parent Packaging.SpreadsheetDocument
?
Through Ancestor, perhaps?
TIA
Update:
The following code has been suggested by Jesper:
WorksheetPart worksheetPart = worksheet.WorksheetPart;
OpenXmlPackage openXmlPackage = worksheetPart.OpenXmlPackage;
SpreadsheetDocument document = (SpreadsheetDocument) openXmlPackage;
That seems to be the correct answer.
Upvotes: 0
Views: 241
Reputation: 2013
WorkSheet
has a WorkSheetPart
property
WorkSheetPart
inherits from OpenXmlPart
which again has an OpenXmlPackage
property, giving the "root" OpenXmlPackage
of this WorkSheetPart
Can you use that?
Upvotes: 1