I am learning to use EPPlus for my C# projects. I would like to be able to identify a worksheet by its immutable "Codename" rather than the user editable "Name" property. I do this all the time in VBA. So here is the code I am trying to implement:
using OfficeOpenXml;
namespace ARTIST.Infrastructure.Excel;
public class InputFile : IDisposable
{
private readonly ExcelPackage package;
private const string defaultFileName = @"C:\Users\Jeff\source\repos\ARTIST\..."; // Full path hidden here.
public InputFile(ExcelPackage package)
{
this.package = package;
}
public ExcelWorkbook OpenWorkbook(string filename = defaultFileName)
{
return package.Workbook;
}
public ExcelWorksheet SelectWorksheet(ExcelWorkbook workbook, string codeName)
{
return workbook.Worksheets.Where(w => w.Name == codeName).First();
}
public void Dispose()
{
package?.Dispose();
GC.SuppressFinalize(this);
}
}
As you can see the lambda expression, the worksheet is only exposing its Name property, but I really want to search for its Codename. Is this possible in EPPlus? Thank you for your help.