I'm trying to loop through unknown worksheet names in a workbook using the SpreadsheetLight Library.
Using the SLDocument sl = new SLDocument("ModifyExistingSpreadsheetOriginal.xlsx", "Sheet1") statement in the examples only allows a string input for the worksheet.
Is there some way to refer to a worksheet index or do something similar to a foreach string sh in Workbook.Sheets loop?
There's a GetWorksheetNames() method that looks like it will do exactly what you want:
var sl = new SLDocument("ModifyExistingSpreadsheetOriginal.xlsx");
foreach (var name in sl.GetWorksheetNames())
{
// do something with each worksheet name
}
From their docs:
Get a list of names of existing worksheets currently in the spreadsheet, excluding chart sheets, macro sheets and dialog sheets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With