ExcelObjectMapper 1.5.8

dotnet add package ExcelObjectMapper --version 1.5.8                
NuGet\Install-Package ExcelObjectMapper -Version 1.5.8                
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="ExcelObjectMapper" Version="1.5.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ExcelObjectMapper --version 1.5.8                
#r "nuget: ExcelObjectMapper, 1.5.8"                
#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.
// Install ExcelObjectMapper as a Cake Addin
#addin nuget:?package=ExcelObjectMapper&version=1.5.8

// Install ExcelObjectMapper as a Cake Tool
#tool nuget:?package=ExcelObjectMapper&version=1.5.8                

publish to nuget ExcelObjectMapper on NuGet NuGet License paypal

ExcelObjectMapper

A simple and efficient .NET library for mapping Excel files to C# objects. This library makes it easy to read Excel files and convert rows to custom C# objects, with minimal code.

Features

  • Read Excel files (.xlsx) with ease
  • Map Excel rows to C# objects
  • Auto-detect column names and map them to C# object properties
  • Easily specify custom column-to-property mappings
  • Supports .NET Standard 2.0 and higher

Getting Started

Installation

Install the ExcelObjectMapper package from NuGet:

Install-Package ExcelObjectMapper

Usage

  1. Create a class that represents the structure of your Excel file:
public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime DateOfBirth { get; set; }
}
  1. Read the Excel file and map the rows to the Employee class:
using ExcelObjectMapper.Readers;

// ...

var filePath = "path/to/your/excel-file.xlsx";
var mapping = new Dictionary<string, string>
{
    { "EmployeeId", "Excel ColumnName1" },
    { "FirstName", "Excel ColumnName2" },
    { "LastName", "Excel ColumnName3" },
    { "DateOfBirth", "Excel ColumnName4" }
};

var excelReader = new ExcelReader<Employee>(filePath);
var employees = excelReader.ReadSheet(mapping);

foreach (var employee in employees)
{
    Console.WriteLine($"{employee.EmployeeId}: {employee.FirstName} {employee.LastName}");
}

Examples

Reading Excel file using byte[]

You can read an Excel file directly from a byte array:

using System.IO;
using ExcelObjectMapper.Readers;

byte[] fileBytes = File.ReadAllBytes("path/to/your/excel-file.xlsx");
var mapping = new Dictionary<string, string>
{
    { "EmployeeId", "Excel ColumnName1" },
    { "FirstName", "Excel ColumnName2" },
    { "LastName", "Excel ColumnName3" },
    { "DateOfBirth", "Excel ColumnName4" }
};

var excelReader = new ExcelReader<Employee>(fileBytes);
var employees = excelReader.ReadSheet(mapping);

foreach (var employee in employees)
{
    Console.WriteLine($"{employee.EmployeeId}: {employee.FirstName} {employee.LastName}");
}
Reading Excel file using IFormFile in ASP.NET Core

When working with file uploads in ASP.NET Core, you can use the IFormFile interface to read an Excel file:

using ExcelObjectMapper;
using Microsoft.AspNetCore.Http;

public async Task<IActionResult> Upload(IFormFile file)
{
    var mapping = ExcelMappingHelper.Create()
    .Add("EmployeeId", "Excel ColumnName1")
    .Add("FirstName", "Excel ColumnName2")
    .Add("LastName", "Excel ColumnName3")
    .Add("DateOfBirth", "Excel ColumnName4")
    .Build();
    
    var excelReader = new ExcelReader<Employee>(file);
    var employees = excelReader.ReadSheet(mapping);

    foreach (var employee in employees)
    {
        Console.WriteLine($"{employee.EmployeeId}: {employee.FirstName} {employee.LastName}");
    }

    return Ok("File processed successfully.");
}

These examples demonstrate how you can read Excel files using different input sources with the ExcelObjectMapper library.

For more information, please refer to the documentation.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
1.5.8 4,569 6/28/2023
1.5.7 128 6/28/2023
1.5.6 126 6/22/2023
1.5.5 131 6/22/2023
1.5.1 163 5/17/2023
1.5.0 132 5/14/2023
1.0.2 131 5/13/2023
1.0.1 139 5/6/2023
1.0.0 140 5/6/2023

Dynamic is supported.