3

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?

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
Brendan Gates
  • 103
  • 1
  • 5

1 Answers1

3

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.

Grant Winney
  • 65,241
  • 13
  • 115
  • 165