I'm trying to use EPPlus to loop through an Excel workbook's sheets, but I'm not having any luck figuring out the syntax.
I'm using C# right now. I was able to get it working in VB.NET, but not C#.
This is what I have that is not working in C#:
object Workbook01 = new OfficeOpenXml.ExcelPackage(WorkbookFilePath).Workbook;
foreach (object sheet01 in Workbook01.Worksheets){
// Code here.
}
This gives an error that says:
'object' does not contain a definition for 'Worksheets' and no extension method 'Worksheets' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
This is what I have in VB.NET that works fine:
Dim Wkbk As Object
Wkbk = New OfficeOpenXml.ExcelPackage(wkbkFilePath).Workbook
For Each sheet01 In Wkbk.Worksheets
' Code here
Next sheet01
Maybe it's a mistake to compare C# to VB.NET for this project, but, either way, I need to figure out how to loop through all sheets with EPPlus in C#.