I put together a simple example using ExcelMapper NuGet package which takes a model and reads data from a specific WorkSheet into a SQL-Server database table via EF Core 8 in a console project and will work in any project type. Note code written with .NET Core 8.
You of course will need to create a class to match your data as I did for my code sample.
Find a working code sample in this project in a GitHub repository.
internal partial class Program
{
static async Task Main(string[] args)
{
try
{
const string excelFile = "Customers.xlsx";
var excel = new ExcelMapper();
var customers = (await excel.FetchAsync<Customers>(excelFile,"Customers")).ToList();
await using var context = new Context();
context.Customers.AddRange(customers);
var affected = await context.SaveChangesAsync();
Console.WriteLine(affected > 0 ? $"Saved {affected} records" : "Failed");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}