I'm iterating over my worksheets like so
WorkbookPart wbPart = doc.WorkbookPart;
SharedStringTablePart sstPart = wbPart.GetPartsOfType<SharedStringTablePart>().First();
SharedStringTable sst = sstPart.SharedStringTable;
foreach (var wsp in wbPart.WorksheetParts)
{
Worksheet ws = wsp.Worksheet;
// i want to do something like this
if (ws.Name == "People_Sheet")
{
}
}
I need to know which sheet i'm processing so I can handle it differently. How can I get the name of the sheet (that is displayed when i open it in excel from here)?
If I get a list of sheets i can find it through attributes
doc.WorkbookPart.Workbook.Sheets.ToList().ForEach(x => Console.WriteLine(x.GetAttribute("name", "").Value));
But what is the relationship between a Sheet and a Worksheet? How can I get the corresponding Sheet or sheet name from a Worksheet?
UPDATE:
So I did find and try this How to retrieve Tab names from excel sheet using OpenXML
However the sheetName did not match up to the worksheet.
foreach (var wsp in wbPart.WorksheetParts)
{
Worksheet worksheet = wsp.Worksheet;
var sheetName = wbPart.Workbook.Descendants<Sheet>().ElementAt(sheetIndex).Name;
var rows = worksheet.Descendants<Row>();
...
}
The rows that are returned from the worksheet do not correspond to the rows that are in the sheet indicated by sheetName. Let me try explain further
I have three worksheets in my excel document - People, Businesses, Products (in that order)
In the first iteration of that loop - the data i get from worksheet rows refers to Products sheet data, but the sheetName says "People"