ExcelAssistant 1.5.4
dotnet add package ExcelAssistant --version 1.5.4
NuGet\Install-Package ExcelAssistant -Version 1.5.4
<PackageReference Include="ExcelAssistant" Version="1.5.4" />
paket add ExcelAssistant --version 1.5.4
#r "nuget: ExcelAssistant, 1.5.4"
// Install ExcelAssistant as a Cake Addin #addin nuget:?package=ExcelAssistant&version=1.5.4 // Install ExcelAssistant as a Cake Tool #tool nuget:?package=ExcelAssistant&version=1.5.4
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 | 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. |
-
net8.0
- FuzzySharp (>= 2.0.2)
- NPOI (>= 2.7.1)
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.4 | 382 | 8/16/2024 |
1.5.3 | 172 | 7/16/2024 |
1.5.2 | 85 | 7/16/2024 |
1.5.1 | 106 | 7/2/2024 |
1.5.0 | 78 | 7/2/2024 |
1.4.0 | 96 | 6/27/2024 |
1.3.6 | 162 | 6/3/2024 |
1.3.5 | 93 | 6/3/2024 |
1.3.3 | 272 | 1/19/2024 |
1.3.2 | 108 | 1/19/2024 |
1.3.1 | 106 | 1/19/2024 |
1.3.0 | 286 | 11/16/2023 |
1.2.4 | 281 | 8/11/2023 |
1.2.3 | 214 | 7/18/2023 |
1.2.2 | 165 | 7/17/2023 |
1.2.0 | 177 | 5/4/2023 |
1.1.2 | 145 | 5/4/2023 |
1.1.1 | 186 | 5/1/2023 |
1.1.0 | 172 | 5/1/2023 |
1.0.0 | 188 | 4/28/2023 |