A .NET library for reading, parsing, and validating Excel files with type-safe operations, data annotation validation, and Entity Framework integration. Supports batch processing with comprehensive error handling. See GitHub for full documentation and examples.
$ dotnet add package SimplyWorks.ExcelImportA .NET library for reading, parsing, and validating Excel files with type-safe operations and comprehensive error handling.
This library consists of two NuGet packages:
Install the core package:
dotnet add package SimplyWorks.ExcelImport
For ASP.NET Core applications, also install the extensions package:
dotnet add package SimplyWorks.ExcelImport.Extensions
public class Order
{
[Required]
public string OrderId { get; set; }
[Required]
public string CustomerName { get; set; }
[Range(0, double.MaxValue)]
public decimal Amount { get; set; }
public DateTime OrderDate { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
services.AddExcelImport();
// Configure your DbContext
services.AddDbContext<YourDbContext>(options =>
options.UseSqlServer(connectionString));
}
public class OrderImportService
{
private readonly ExcelService _excelService;
public OrderImportService(ExcelService excelService)
{
_excelService = excelService;
}
public async Task ImportOrders(string excelFileUrl)
{
var options = new TypedParseToJsonOptions
{
TypeAssemblyQualifiedName = typeof(Order).AssemblyQualifiedName,
NamingStrategy = JsonNamingStrategy.SnakeCase
};
// Load and validate Excel file
var container = await _excelService.LoadExcelFileInfo(excelFileUrl, options);
// Check for validation errors
if (container.Sheets.Any(sheet => sheet.HasErrors()))
{
// Handle validation errors
return;
}
// Import valid data
await _excelService.Import(excelFileUrl, options);
}
}
public class OrderQueryService
{
private readonly IExcelQueryable _excelQueryable;
public OrderQueryService(IExcelQueryable excelQueryable)
{
_excelQueryable = excelQueryable;
}
public async Task<IEnumerable<Order>> GetValidOrders(string reference, int pageIndex = 0, int pageSize = 100)
{
var options = new ExcelQueryValidatedOptions
{
Reference = reference,
PageIndex = pageIndex,
PageSize = pageSize,
RowStatus = QueryRowStatus.Valid
};
return await _excelQueryable.Get<Order>(options);
}
}
Main service for importing Excel files with validation and error handling.
Interface for reading Excel files and sheets with support for:
Repository pattern implementation for storing Excel import metadata and results.
Generic sheet reader for type-safe Excel data parsing.
Built-in support for:
TypeAssemblyQualifiedName: Target type for parsingNamingStrategy: JSON naming strategy (SnakeCase, CamelCase, etc.)SheetsOptions: Configuration for multiple sheetsThe library includes Entity Framework entities for tracking:
ExcelFileRecord: Excel file metadataSheetRecord: Individual sheet informationRowRecord: Row-level data and validation resultsCellRecord: Cell-level dataBatch and BatchItem: Batch processing trackingThis project is licensed under the MIT License - see the LICENSE file for details.
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
For issues and questions:
This library is part of the SimplyWorks ecosystem: