Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through unknown worksheet names in a workbook using the SpreadsheetLight Library

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?

like image 629
Brendan Gates Avatar asked Oct 27 '25 16:10

Brendan Gates


1 Answers

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.

like image 123
Grant Winney Avatar answered Oct 30 '25 07:10

Grant Winney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!