ExcelAssistant 1.6.2
dotnet add package ExcelAssistant --version 1.6.2
NuGet\Install-Package ExcelAssistant -Version 1.6.2
<PackageReference Include="ExcelAssistant" Version="1.6.2" />
paket add ExcelAssistant --version 1.6.2
#r "nuget: ExcelAssistant, 1.6.2"
// Install ExcelAssistant as a Cake Addin #addin nuget:?package=ExcelAssistant&version=1.6.2 // Install ExcelAssistant as a Cake Tool #tool nuget:?package=ExcelAssistant&version=1.6.2
ExcelAssistant
ExcelAssistant is a .NET library that provides a simple and efficient way to work with Microsoft Excel files. With ExcelAssistant, you can easily read, write, and manipulate Excel files in your .NET applications.
Features
- Read data from Excel files
- Write data to Excel files
- Manipulate Excel files (add, delete, rename sheets, set sheet color, etc.)
- Set cell values and formats
- Set column width and row height
- Apply styles to cells and sheets
Installation
You can install ExcelAssistant using NuGet:
Install-Package ExcelAssistant
.NET CLI Console
dotnet add package ExcelAssistant
Getting Started
Writing a Excel File
Let's look at how we can create and write excel files. In our example, we will use the simple "Report" record model, but it can be any other c# class.
using ExcelAssistant;
//Create a list of test data
var records = new List<Report>()
{
new("Maki", "test@gmail.com", 100),
new("Smith", "test1@gmail.com", 200),
new("Lara", "test2@gmail.com", 450),
};
//Open or create the file for reading (the file will be in the project output directory)
using var stream = File.OpenWrite("records.xls");
//Create an instance of ExcelWriter.
using var writer = new ExcelWriter();
//Write records into the file
writer.WriteRecords(stream, records);
//"Report" model
public record Report(string Name, string Email, decimal Balance);
Also, we can change our output file header by adding configuration:
using var stream = File.OpenWrite("records.xls");
using var writer = new ExcelWriter();
writer.AddMapping<Report>(r => r.Name, "Customer Name");
writer.AddMapping<Report>(r => r.Email, "Customer Email");
writer.WriteRecords(stream, records);
Example of recording various models across multiple Excel worksheets.
using var stream = File.OpenWrite("records.xls");
using var writer = new ExcelWriter();
writer.AddMapping<Report>(r => r.Type, "Activity Type");
writer.AddMapping<Report>(r => r.Date, "Activity Date");
writer.AddMapping<Customer>(c => c.Name, "Customer Name");
writer.AddMapping<Customer>(c => c.Email, "Customer Email");
writer.BuildSheet(Customers, "Customeers");
writer.BuildSheet(report, "Report");
writer.CopyTo(stream);
Reading files where table headers are the same as c# model properties:
using var stream = File.OpenRead("records.xls");
using var reader = new ExcelReader(stream);
var records = reader.Read<Report>();
Now reading files using the configuration mentioned above
using var stream = File.OpenRead("records.xls");
using var reader = new ExcelReader(stream, config);
var records = reader.Read<Report>();
The library provides the opportunity for manual reading. Method Read return IEnumerable<Dictionary<string,string>> where key is the column name and value is the data for the specific row.
using var stream = File.OpenRead("records.xls");
using var reader = new ExcelReader(stream, config);
var records = reader
.Read()
.Select(rowData => new Report(
rowData[nameof(Report.Name)],
rowData[nameof(Report.Email)],
decimal.Parse(rowData[nameof(Report.Balance)])
))
.ToList();
License
ExcelAssistant is released under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- FuzzySharp (>= 2.0.2)
- NPOI (>= 2.7.2)
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.6.2 | 105 | 12/17/2024 |
1.6.1 | 69 | 12/17/2024 |
1.6.0 | 68 | 12/17/2024 |
1.5.4 | 489 | 8/16/2024 |
1.5.3 | 182 | 7/16/2024 |
1.5.2 | 93 | 7/16/2024 |
1.5.1 | 114 | 7/2/2024 |
1.5.0 | 86 | 7/2/2024 |
1.4.0 | 104 | 6/27/2024 |
1.3.6 | 170 | 6/3/2024 |
1.3.5 | 101 | 6/3/2024 |
1.3.3 | 280 | 1/19/2024 |
1.3.2 | 114 | 1/19/2024 |
1.3.1 | 114 | 1/19/2024 |
1.3.0 | 294 | 11/16/2023 |
1.2.4 | 287 | 8/11/2023 |
1.2.3 | 220 | 7/18/2023 |
1.2.2 | 171 | 7/17/2023 |
1.2.0 | 183 | 5/4/2023 |
1.1.2 | 151 | 5/4/2023 |
1.1.1 | 192 | 5/1/2023 |
1.1.0 | 178 | 5/1/2023 |
1.0.0 | 194 | 4/28/2023 |