EasyExcel.Tools 4.0.0.3

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

EasyExcel - A Simple Excel Utility for C#

EasyExcel is a lightweight utility for reading from and writing to Excel files in C#. It is built using only the built-in features of .NET Core(OpenXML), without relying on any external libraries or packages. This makes it a great choice for projects where you want to avoid additional dependencies.

Features

  • Read Excel Files: Convert Excel files into a list of strongly-typed objects.
  • Write Excel Files: Export a list of objects or a DataTable to an Excel file.
  • No External Dependencies: Uses only the built-in features of .NET Core.
  • Flexible: Supports multiple sheets and custom column names via attributes.
  • Lightweight: Minimal overhead and easy to integrate into existing projects.

Installation

Since EasyExcel is a single-file utility, you can simply copy the EasyExcel.cs file into your project and start using it.

Usage

Reading from Excel

To read data from an Excel file into a list of objects, use the ReadExcelFile method:

[ExcelSheetName(SheetName ="Sheet1")]
public class Person
{
[ExcelColumnName(ColumnName = "CustomerName")]
    public string Name { get; set; }
[ExcelColumnName(ColumnName = "CustomerAge")]
    public int Age { get; set; }
[ExcelColumnName(ColumnName = "BirthDate")]
    public DateTime BirthDate { get; set; }
}

using (var stream = new FileStream("path_to_excel_file.xlsx", FileMode.Open))
{
    var people = EasyExcel.ReadExcelFile<Person>(stream);
    foreach (var person in people)
    {
        Console.WriteLine($"Name: {person.Name}, Age: {person.Age}, BirthDate: {person.BirthDate}");
    }
}

Writing to Excel

To write a list of objects to an Excel file, use the ExportToExcel method:

public class Person
{
[ExcelExport(DisplayName = "Person Name")]
    public string Name { get; set; }
[ExcelExport(DisplayName = "Person Age")]
    public int Age { get; set; }
    public DateTime BirthDate { get; set; }
}
var people = new List<Person>
{
    new Person { Name = "John Doe", Age = 30, BirthDate = new DateTime(1990, 1, 1) },
    new Person { Name = "Jane Doe", Age = 25, BirthDate = new DateTime(1995, 5, 5) }
};

var excelBytes = EasyExcel.ExportToExcel(people, "People");
File.WriteAllBytes("output.xlsx", excelBytes);

Customizing Column Names and Sheet Names

You can customize the column names and sheet names using attributes:

[ExcelSheetName("Employees")]
public class Employee
{
    [ExcelColumnName("Full Name")]
    public string Name { get; set; }

    [ExcelColumnName("Age in Years")]
    public int Age { get; set; }

    [ExcelColumnName("Date of Birth")]
    public DateTime BirthDate { get; set; }
}

Handling Multiple Sheets

You can read data from multiple sheets in a single Excel file:

using (var stream = new FileStream("path_to_excel_file.xlsx", FileMode.Open))
{
    var (people, employees) = EasyExcel.ReadExcelFile<Person, Employee>(stream);
}

How Using in Api

You can use in api method like this:

var result = EasyExcel.ExportToExcel(oNewList);
FileContentResult content = new FileContentResult(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return content;

Attributes

  • ExcelColumnNameAttribute: Specifies the column name in the Excel file.

  • ExcelSheetNameAttribute: Specifies the sheet name in the Excel file.

  • ExcelExportAttribute: Specifies whether a property should be included in the export and its display name.

Limitations

  • Excel Format: Only supports .xlsx files (Excel 2007 and later).

  • Data Types: Supports basic data types like int, double, decimal, bool, DateTime, and string.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.

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 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. 
.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
4.0.0.3 113 10/18/2025
4.0.0 113 10/18/2025
3.0.0.3 124 10/18/2025
1.0.3 186 2/15/2025
1.0.2 167 2/13/2025
1.0.1 159 2/13/2025