EasyExcel 1.0.0

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

// Install EasyExcel as a Cake Tool
#tool nuget:?package=EasyExcel&version=1.0.0

What's EasyExcel?

EasyExcel is a simple but very powerful tool that easily converts objects to excel and excel to objects.

What exactly you can do using EasyExcel?

  • Convert an excel file into a list of objects;
  • Convert a list object into an excel file;

The artfacts below will be used on next examples:

Excel Spreadsheet

| Name                  | Gender | Date of Birth | Height | Weight |
| --------------------- | ------ | ------------- | ------ | ------ | 
| Adam Braun            | 0      | 1952-05-02    | 7.41   | 162.81 |
| Allen Swaniawski      | 0      | 1974-03-24    | 6.62   | 387.32 |
| Guy Tromp             | 0      | 1992-02-18    | 7.45   | 161.84 |
| Edgar Haag            | 0      | 1978-04-22    | 7.55   | 398.99 |

Class (Object)

    public class Employee
    {
        public string Name { get; set; }
        public Gender Gender { get; set; }
        public DateTime DateOfBirth { get; set; }
        public decimal Height { get; set; }
        public decimal Weight { get; set; }

        public Employee() { }

        public Employee(
            string name,
            Gender gender,
            DateTime dateOfBirth,
            decimal height,
            decimal weight)
        {
            Name = name;
            Gender = gender;
            DateOfBirth = dateOfBirth;
            Height = height;
            Weight = weight;
        }
    }

    public enum Gender
    {
        Male,
        Female
    }

Converting a list object into an excel file

1 - Create an ExcelByColumnIndex object list that maps the object attributes to excel column, as shown below

var columnsMapping = new List<ExcelByColumnIndex> {
    new ExcelByColumnIndex(1, "Name", "Name"),
    new ExcelByColumnIndex(2, "Gender", "Gender"),
    new ExcelByColumnIndex(3, "DateOfBirth", "Date of Birth"),
    new ExcelByColumnIndex(4, "Height", "Height"),
    new ExcelByColumnIndex(5, "Weight", "Weight")
};

You can you ExcelByColumnLetter instead of ExcelByColumnIndex in order to inform A, B, C ... to indicate the columns

The columns mapping object list will be responsible to tell which attributes go in wich column and also tells what's the header text

2 - Convert object list to file

var employees = new List<Employee> {
    new Employee("Adam Braun", Gender.Male, DateTime.Parse("1952-05-02"),  7.41m, 162.81m),
    new Employee("Allen Swaniawski", Gender.Male, DateTime.Parse("1974-03-24"),  6.62m, 387.32m),
    new Employee("Guy Tromp", Gender.Male, DateTime.Parse("1992-02-18"), 7.45m, 161.84m),
    new Employee("Edgar Haag", Gender.Male, DateTime.Parse("1978-04-22"), 7.55m, 398.99m),
    ...
};

var spreadsheetFilePath = "<your excel file path>";
ObjectToExcelConverter.CreateFileFromObjectCollection(columnsMapping, employees, spreadsheetFilePath);  

Converting excel files into a list of objects

1 - Create an ObjectByColumnIndex object list that maps the excel column to object attributes, as shown below

var columnsMapping = new List<ObjectByColumnIndex> {
    new ObjectByColumnIndex(1, "Name", true),
    new ObjectByColumnIndex(2, "Gender", true),
    new ObjectByColumnIndex(3, "DateOfBirth", true),
    new ObjectByColumnIndex(4, "Height", true),
    new ObjectByColumnIndex(5, "Weight", true)
};

You can you ObjectByColumnLetter instead of ObjectByColumnIndex in order to inform A, B, C ... to indicate the columns

The columns mapping object list will be responsible to tell in which column is the data for each attribute and also tells if that value is required.

2 - Convert excel to object list 2.1 - From a excel file path

var spreadsheetFilePath = "<your excel file path>";
var employees = ExcelToObjectConverter.ToObjectCollection<Employee>(spreadsheetFilePath, columnsMapping);

2.2 - From a excel file stream

var spreadsheetFilePath = "<your excel file path>";
var spreadsheetStream = File.OpenRead(spreadsheetFilePath);
var employees = ExcelToObjectConverter.ToObjectCollection<Employee>(spreadsheetStream, columnsMapping);
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. 
.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.
  • .NETStandard 2.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EasyExcel:

Package Downloads
SPWProductInformationService.Services

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 5,140 1/10/2019