I am trying to read an existing spreadsheet using Blazor server under net8.0 and the latest version of EPPlus (7.0.6). The spreadsheet I'm trying to read has 1 (one) worksheet. When I inspect the Worksheets collection it has a count of zero.
I tried to use the position Id of zero
using var package = new ExcelPackage("spreadsheet.xlsx");
var sheet = package.Workbook.Worksheets[0];
Then I tried naming it
using var package = new ExcelPackage("spreadsheet.xlsx");
var sheet = package.Workbook.Worksheets["name"];
I know this works in net7.0 as I wrote a console app to do the same thing. But I need this to work in my Blazor App. It's obvious that it's not seeing/reading the sheet. Is this a bug in EPPlus?
I've also tried previous versions of EPPlus with the same result.
Full Code
@using OfficeOpenXml
<PageTitle>Home</PageTitle>
<h1>Test Spreadsheet</h1>
@if (errors.Any())
{
<h2>Errors</h2>
<ul class="text-danger">
@foreach (var e in errors)
{
<li>@e</li>
}
</ul>
}
@code {
private List<string> errors = new();
protected override void OnInitialized()
{
errors.Clear();
try
{
using var package = new ExcelPackage("spreadsheet.xlsx");
var sheet = package.Workbook.Worksheets[0];
}
catch (Exception ex)
{
errors.Add(ex.Message);
}
}
}
I am sorry I just worked this out for myself. Even though the ExcelPackage object is not null I needed the full path not just a relitive path to access the actual file.
My appogies to all.