oleworldcoder
oleworldcoder

Reputation: 91

How to go from Worksheet to SpreadsheetDocument?

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

Answers (1)

Related Questions