IntNovAction.Utils.ExcelImporter 2.2.1

dotnet add package IntNovAction.Utils.ExcelImporter --version 2.2.1
                    
NuGet\Install-Package IntNovAction.Utils.ExcelImporter -Version 2.2.1
                    
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="IntNovAction.Utils.ExcelImporter" Version="2.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IntNovAction.Utils.ExcelImporter" Version="2.2.1" />
                    
Directory.Packages.props
<PackageReference Include="IntNovAction.Utils.ExcelImporter" />
                    
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 IntNovAction.Utils.ExcelImporter --version 2.2.1
                    
#r "nuget: IntNovAction.Utils.ExcelImporter, 2.2.1"
                    
#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 IntNovAction.Utils.ExcelImporter@2.2.1
                    
#: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=IntNovAction.Utils.ExcelImporter&version=2.2.1
                    
Install as a Cake Addin
#tool nuget:?package=IntNovAction.Utils.ExcelImporter&version=2.2.1
                    
Install as a Cake Tool

IntNovAction.Utils.ExcelImporter

Utility to import excel data into POCOs

The usage is quite simple:

// Define the destination POCO class
class SampleImportInto
{
    public int IntColumn { get; set; }
    public int? NullableIntColumn { get; set; }
    public decimal DecimalColumn { get; set; }
    public decimal? NullableDecimalColumn { get; set; }
    public float FloatColumn { get; set; }
    public float? NullableFloatColumn { get; set; }
    public string StringColumn { get; set; } 
    public DateTime DateColumn { get; set; }
    public DateTime? NullableDateColumn { get; set; }
    public bool BooleanColumn { get; set; }
    public bool? NullableBooleanColumn { get; set; }
}

// Read the excel file 
using (var stream = File.OpenRead("d:\ExcelWithData.xlsx"))
{
    // Create the typed importer
    var importer = new Importer<SampleImportInto>();

    // Configure
    importer
        .SetErrorStrategy(ErrorStrategy.AddElement)
        .FromExcel(stream, "Sheet Name")
        .For(p => p.IntColumn, "Int Column")
        .For(p => p.FloatColumn, "Float Column")
        .For(p => p.DecimalColumn, "Decimal Column")
        .For(p => p.NullableIntColumn, "Nullable Int Column")
        .For(p => p.NullableFloatColumn, "Nullable Float Column")
        .For(p => p.NullableDecimalColumn, "Nullable Decimal Column")
        .For(p => p.StringColumn, "String Column")
        .For(p => p.DateColumn, "Date Column")
        .For(p => p.NullableDateColumn, "Nullable Date Column")
        .For(p => p.BooleanColumn, "Boolean Column")
        .For(p => p.NullableBooleanColumn, "Nullable Boolean Column");

    // Import
    var importResults = importer.Import();
    
    // Read the imported objects...
    var numImportedItems = importResults.ImportedItems.Count();

    // Check the errors...
    var numImportedObjects = importResults.Errors.Count();
}

Error Handling

You can control how errors are handled during import using SetErrorStrategy:

  • ErrorStrategy.AddElement: Adds the row even if it has errors.
  • ErrorStrategy.DoNotAddElement: Skips rows with errors.

Nested Objects

Supports nested objects (1-1 relationships). The default constructor must create the nested objects:

class InnerClass { public int PropInt { get; set; } }
class ClassWithInnerClass {
    public InnerClass Inner { get; set; } = new InnerClass();
    public int TestInt { get; set; }
}

var importer = new Importer<ClassWithInnerClass>()
    .For(p => p.Inner.PropInt, "Inner Column")
    .For(p => p.TestInt, "Base Column");

Excel Template Generation

You can generate an Excel template for your import:

var importer = new Importer<SampleImportInto>()
    .For(p => p.IntColumn, "Int Column")
    .For(p => p.StringColumn, "String Column");

using (var excelStream = importer.GenerateExcel())
{
    // Save or send the template
}

With Sample Data

var sampleData = new List<SampleImportInto> { new SampleImportInto { IntColumn = 1, StringColumn = "Test" } };
using (var excelStream = importer.GenerateExcel(sampleData))
{
    // Save or send the template with sample rows
}

Duplicated Column Strategies

Control how duplicated columns are handled with SetDuplicatedColumnsStrategy:

  • DuplicatedColumnStrategy.TakeFirst: Uses the first occurrence.
  • DuplicatedColumnStrategy.TakeLast: Uses the last occurrence.
  • DuplicatedColumnStrategy.RaiseError: Fails import if duplicates are found.

Custom row processing with CustomFor

You can execute custom logic for each imported row using CustomFor. This method receives a dictionary with the column values and the destination object, allowing you to process or validate data as needed:

using (var stream = File.OpenRead("d:\ExcelWithData.xlsx"))
{
    var importer = new Importer<SampleImportInto>()
        .FromExcel(stream, "Sheet Name")
        .For(p => p.IntColumn, "Int Column")
        .CustomFor((Dictionary<string, string> rowValues, SampleImportInto destination) =>
        {
            // Example: log or transform values
            Console.WriteLine($"Row IntColumn value: {rowValues["Int Column"]}");
            // You can also modify 'destination' here
        });

    var importResults = importer.Import();
}

You can combine CustomFor with duplicated column strategies:

importer
    .SetDuplicatedColumnsStrategy(DuplicatedColumnStrategy.TakeFirst) // or TakeLast, RaiseError
    .CustomFor((rowValues, destination) =>
    {
        // Will receive the value according to the selected strategy
        Console.WriteLine($"IntColumn: {rowValues["Int Column"]}");
    });

Row Index Mapping

You can map the Excel row index to a property in your POCO:

class SampleImportInto { public int RowIndex { get; set; } /* ... */ }

importer.SetRowIndex(p => p.RowIndex);

Supported Types

The importer supports the following property types:

  • int, int?
  • decimal, decimal?
  • float, float?
  • string
  • DateTime, DateTime?
  • bool, bool?

Dependencies & Compatibility


Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.1 180 9/24/2025
2.2.0 180 9/23/2025
2.1.1 1,781 6/24/2022
2.1.0 588 6/24/2022
2.0.0 557 8/25/2021
0.0.7 2,334 3/12/2019
0.0.6 884 12/29/2018
0.0.5 1,001 9/24/2018
0.0.4 1,046 9/17/2018
0.0.3 986 9/17/2018
0.0.2 1,007 9/14/2018
0.0.1 1,004 9/14/2018

Changes in namespaces, Now you can specify the initial coordinates for the importation