ExcelAssistant 1.3.3

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

// Install ExcelAssistant as a Cake Tool
#tool nuget:?package=ExcelAssistant&version=1.3.3

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:

var config = new ExcelConfiguration
{
    HumanReadableHeaders = new Dictionary<string, string>()
    {
        {nameof(Report.Name), "Customer Name"},
        {nameof(Report.Email), "Customer Email"},
    }
};

using var stream = File.OpenWrite("records.xls");
using var writer = new ExcelWriter(config);
writer.WriteRecords(stream, records);

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 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. 
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.3.3 204 1/19/2024
1.3.2 74 1/19/2024
1.3.1 73 1/19/2024
1.3.0 255 11/16/2023
1.2.4 253 8/11/2023
1.2.3 188 7/18/2023
1.2.2 143 7/17/2023
1.2.0 154 5/4/2023
1.1.2 123 5/4/2023
1.1.1 158 5/1/2023
1.1.0 149 5/1/2023
1.0.0 155 4/28/2023