DoIt.ExcelWriter 1.2.3

dotnet add package DoIt.ExcelWriter --version 1.2.3                
NuGet\Install-Package DoIt.ExcelWriter -Version 1.2.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.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DoIt.ExcelWriter --version 1.2.3                
#r "nuget: DoIt.ExcelWriter, 1.2.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.2.3

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

DoIt.ExcelWriter

NuGet Badge

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 an 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

Create an ExcelWriter instance. Then, either add one (or more) typed sheets to it and write typed rows to the sheet, or add one (or more) sheets accepting a System.Data.Common.DbDataReader as source and stream database results directly to an Excel file/stream (without having to map each row to a .NET class/record).

using DoIt.ExcelWriter;

// Create an IExcelWriter and either provide a filename or a Stream instance as destination.
await using (var writer = ExcelWriterFactory.Create("test.xlsx"))
{
    // Add a typed 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 { ... });
    }
    // Add a sheet accepting a DbDataReader.
    await using (var sheet = await writer.AddDbDataReaderSheetAsync("DbDataReader sheet"))
    // Get you DbDataReader instance somehow.
    await using (var reader = await GetDatabaseQueryResultsAsync())
    {
        // Write all rows at once. It is also possible to write one row at a time, leaving
        // responsibility of advancing the reader to the caller.
        await sheet.WriteAllAsync(reader);
    }
}

When creating typed Excel sheets, 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, sbyte, short, ushort, int, uint, long and ulong)
  • Floating points (float and double)
  • decimal
  • System.DateTime and System.DateTimeOffset
  • System.Uri and DoIt.ExcelWriter.Hyperlink (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.

The library, furthermore, does not used shared strings (since that would require that all string are known in advanced). This may lead to larger than necessary Excel files.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.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 (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