DoIt.ExcelWriter 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package DoIt.ExcelWriter --version 1.0.3                
NuGet\Install-Package DoIt.ExcelWriter -Version 1.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="DoIt.ExcelWriter" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DoIt.ExcelWriter --version 1.0.3                
#r "nuget: DoIt.ExcelWriter, 1.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.
// Install DoIt.ExcelWriter as a Cake Addin
#addin nuget:?package=DoIt.ExcelWriter&version=1.0.3

// Install DoIt.ExcelWriter as a Cake Tool
#tool nuget:?package=DoIt.ExcelWriter&version=1.0.3                

DoIt.ExcelWriter

A "forward only" Excel writer.

Why should I use this?

If you need to create Excel files based on large data sets in a fast and memory efficient manner, this is for you! This library allows you to write Excel data and stream the resulting Excel file as each row is written. This basically means that a ASP.NET application can stream the results of a database query, for example, directly to a client only holding a single result row in memory at any time.

Sound great, how do I use it?

First, add the library to you project.

dotnet add package DoIt.ExcelWriter

Then create an ExcelWriter instance, add one (or more) typed sheets to it and write rows to the sheet.

// Create an ExcelWriter and either provide a filename or a Stream instance as destination.
await using (var writer = new ExcelWriter("test.xlsx"))
// Add a sheet. Note that the sheet is typed and only accepts rows of the specified type!
await using (var sheet = await writer.AddSheetAsync<MyDataType>("Sheet1"))
{
    // Each call to WriteAsync will write all public properties as a single row.
    await sheet.WriteAsync(new MyDataType { ... });
}

You can control the apperance of the produced Excel file by using the ExcelColumnAttribute attribute on your data type's public properties. This attribute allows you to

  • change the property's column title from the default value (the property name),
  • exclude (i.e ignore) a property,
  • set a custom width of a property's column.
public record MyDataType
{
    [ExcelColumn(Ignore = true)] // Exclude/ignore the column when writing the Excel data.
    public int Id { get; init; }

    [ExcelColumn("First name")] // Change the default column title.
    public string FirstName { get; init; } = string.Empty;

    [ExcelColumn(CustomWidth = 64)] // Set a custom width of the column.
    public string? Comment { get; init; }
}

The library handles properties of the following types:

  • Integers (byte, short, int and long)
  • Floating points (float and double)
  • decimal
  • DateTime and DateTimeOffset
  • Uri (becomes clickable links)
  • bool
  • string

Values of properties of other types are ignored.

Note that the API only has async methods and accepts CancellationTokens whenever possible.

Fantastic! So what's the catch?

Since the library streams Excel data as each row is written, it is not possible to make changes to data already written. Since column definitions (like the width of a column) comes before the actual data in an Excel file, it is, for example, not possible to change the column width based on the actual data. The library does, however, set sensible default column widths based on each column's title and data type.

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DoIt.ExcelWriter:

Package Downloads
DoIt.ExcelWriter.AspNetCore

Extensions for simplifying usage of the "forward only" Excel writer DoIt.ExcelWriter from ASP.NET Core applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.3 294 8/1/2024
1.2.2 2,043 3/3/2023
1.2.1 342 1/4/2023
1.2.0 317 1/4/2023
1.1.4 492 9/29/2022
1.1.2 418 8/17/2022
1.1.1 433 8/13/2022
1.1.0 433 8/1/2022
1.0.5 447 7/26/2022
1.0.4 409 7/26/2022
1.0.3 441 7/11/2022
1.0.2 425 7/6/2022
1.0.1 446 7/6/2022
1.0.0 433 7/4/2022