I’m using version 1.0 of Microsoft’s OpenXML SDK to do some basic parsing of .xlsx files. I can get and parse the worksheets, and I can get a list of worksheet names, but I cannot for the life of me figure out how to link up what name goes with what worksheet.
I understand that an element like <sheet name="My Sheet" sheetId="1" r:id="rId1"/> in the workbook is linked up to a specific worksheet via the relationships defined in xl/_rels.xml, but I can’t see where any of the relationship info is exposed in the API.
I’m using C#, but any VB.NET examples would be just as helpful.
I feel like this should be dead simple, but I can’t figure it out. It also looks like it may be more straightforward in v2.0 of the SDK, but upgrading isn’t an option at the moment.
Argh… yes, it ended up being dead simple. The
WorkbookPartclass exposes aWorksheetPartsproperty that I was hung up on using, but it also exposes aGetPartById(relationshipId)method.Given a list of
<sheet/>elements from the workbook XML – each of which contains both a name and a relationship id – I just needed to retrieve each WorksheetPart by id.