SimplyWorks.ExcelImport 8.1.0

dotnet add package SimplyWorks.ExcelImport --version 8.1.0
                    
NuGet\Install-Package SimplyWorks.ExcelImport -Version 8.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimplyWorks.ExcelImport" Version="8.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimplyWorks.ExcelImport" Version="8.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SimplyWorks.ExcelImport" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimplyWorks.ExcelImport --version 8.1.0
                    
#r "nuget: SimplyWorks.ExcelImport, 8.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SimplyWorks.ExcelImport@8.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimplyWorks.ExcelImport&version=8.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SimplyWorks.ExcelImport&version=8.1.0
                    
Install as a Cake Tool

SimplyWorks ExcelImport

Build and Publish NuGet Package NuGet NuGet Extensions License: MIT

A .NET library for reading, parsing, and validating Excel files with type-safe operations and comprehensive error handling.

Features

  • Excel File Reading: Read Excel files (.xlsx, .xls) using ExcelDataReader
  • Type-Safe Parsing: Parse Excel data into strongly-typed C# objects
  • Data Validation: Built-in validation using data annotations
  • Batch Processing: Support for batch imports with error tracking
  • Sheet Mapping: Map Excel sheets to different types with flexible column mapping
  • Query Interface: Query imported Excel data with filtering and pagination
  • Entity Framework Integration: Store and query Excel data using Entity Framework

Packages

This library consists of two NuGet packages:

  • SimplyWorks.ExcelImport: Core library with Excel reading and parsing functionality
  • SimplyWorks.ExcelImport.Extensions: ASP.NET Core dependency injection extensions

Installation

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

Quick Start

1. Define Your Data Model

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; }
}

2. Configure Services (ASP.NET Core)

public void ConfigureServices(IServiceCollection services)
{
    services.AddExcelImport();
    // Configure your DbContext
    services.AddDbContext<YourDbContext>(options => 
        options.UseSqlServer(connectionString));
}

3. Import Excel Data

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);
    }
}

4. Query Imported Data

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);
    }
}

Core Components

ExcelService

Main service for importing Excel files with validation and error handling.

IExcelReader

Interface for reading Excel files and sheets with support for:

  • Multiple sheet processing
  • Column mapping
  • Row-by-row reading

ExcelRepo

Repository pattern implementation for storing Excel import metadata and results.

SheetReader<T>

Generic sheet reader for type-safe Excel data parsing.

Data Validation

Built-in support for:

  • Data annotation validation
  • Type conversion validation
  • Custom validation rules

Configuration Options

TypedParseToJsonOptions

  • TypeAssemblyQualifiedName: Target type for parsing
  • NamingStrategy: JSON naming strategy (SnakeCase, CamelCase, etc.)
  • SheetsOptions: Configuration for multiple sheets

SheetMappingOptions

  • Column mapping configuration
  • Sheet selection options
  • Validation rules

Entity Framework Integration

The library includes Entity Framework entities for tracking:

  • ExcelFileRecord: Excel file metadata
  • SheetRecord: Individual sheet information
  • RowRecord: Row-level data and validation results
  • CellRecord: Cell-level data
  • Batch and BatchItem: Batch processing tracking

Dependencies

  • ExcelDataReader: For reading Excel files
  • Newtonsoft.Json: JSON serialization
  • Entity Framework Core: Data persistence
  • SimplyWorks Libraries: Additional utilities and extensions

Target Framework

  • .NET Standard 2.1 (Core library)
  • .NET Core 3.1 (Extensions package)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

Support

For issues and questions:

This library is part of the SimplyWorks ecosystem:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SimplyWorks.ExcelImport:

Package Downloads
SimplyWorks.ExcelImport.Extensions

ASP.NET Core dependency injection extensions for SimplyWorks.ExcelImport. Provides easy service registration for Excel import functionality with Entity Framework integration. See GitHub for full documentation and examples.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.1.0 259 9/16/2025
2.0.14 3,170 7/23/2024
2.0.10 1,641 12/13/2020
2.0.9 1,004 10/28/2020
2.0.8 4,868 10/28/2020
2.0.7 624 10/28/2020
2.0.6 638 10/27/2020
2.0.5 605 10/27/2020
2.0.4 637 10/27/2020
2.0.3 987 8/1/2020