SimpleExcelExporter 1.3.1

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

// Install SimpleExcelExporter as a Cake Tool
#tool nuget:?package=SimpleExcelExporter&version=1.3.1

SimpleExcelExporter

NuGet version (SimpleExcelExporter) .NET

This C# library helps export data to Excel .xlsx file.

Internally it uses the Microsoft DocumentFormat.OpenXml library. Unlike DocumentFormat.OpenXml, this library doesn't aim to produce any possible kind of .xlsx file but focus on the use case where a user of your application wants to export data to an Excel file. Of course you can use DocumentFormat.OpenXml directly but we believe this library is simpler and is less error prone for that particular use case.

How to use?

  1. Let's say you have a Player class in your code.
public class Player
{
  public DateTime? DateOfBirth { get; set; }

  public string? PlayerName { get; set; }

  public int? NumberOfVictory { get; set; }

  public bool? IsActiveFlag { get; set; }

  public double? Size { get; set; }

  public decimal? Salary { get; set; }
}

and a team class

public class Team
{
  private ICollection<Player>? _players;

  public ICollection<Player> Players
  {
    get => _players ??= new HashSet<Player>();
  }
}
  1. Use SimpleExcelExporter to generate an Excel file: The following snippet comes from SimpleExcelExporterExample
// Instanciate the objects to export
var team = new Team
{
  Players =
{
  new Player
  {
    PlayerName = "Alexandre",
    Size = 1.93d,
    DateOfBirth = new DateTime(1974, 02, 01),
    IsActiveFlag = true,
    NumberOfVictory = 45,
    Salary = 2000.50m,
  },
  new Player
  {
    PlayerName = "Elina",
    Size = 1.72d,
    DateOfBirth = new DateTime(1990, 10, 13),
    IsActiveFlag = true,
    NumberOfVictory = 52,
    Salary = 2141.25m,
  }
},
};

// Create a temp directory
var n = DateTime.Now;
var tempDi = new DirectoryInfo($"ExampleOutput-{n.Year - 2000:00}-{n.Month:00}-{n.Day:00}-{n.Hour:00}{n.Minute:00}{n.Second:00}");
tempDi.Create();

// Export team to an excel file
using var memoryStream = new MemoryStream();
using var streamWriter = new StreamWriter(memoryStream);
SpreadsheetWriter spreadsheetWriter = new SpreadsheetWriter(streamWriter.BaseStream, team);
spreadsheetWriter.Write();
using FileStream file = new FileStream(Path.Combine(tempDi.FullName, "Team.xlsx"), FileMode.Create, FileAccess.Write);
memoryStream.WriteTo(file);

How to configure export ?

  1. If you want to configure the column names and/or the sheet name, create a resource file. In the following code I assume you have a resource file

  2. Anotate your classes The following snippet comes from SimpleExcelExporterExample

public class Team
{
  private ICollection<Player>? _players;

  [SheetName(typeof(TeamRes), "SheetName")]
  [EmptyResultMessage(typeof(TeamRes), "EmptyResultMessage")]
  public ICollection<Player> Players
  {
    get => _players ??= new HashSet<Player>();
  }
}

The following snippet comes from SimpleExcelExporterExample

public class Player
{
  [CellDefinition(CellDataType.Date)]
  [Header(typeof(TeamRes), "DateOfBirthColumnName")]
  [Index(2)]
  public DateTime? DateOfBirth { get; set; }

  [CellDefinition(CellDataType.String)]
  [Header(typeof(TeamRes), "PlayerNameColumnName")]
  [Index(1)]
  public string? PlayerName { get; set; }

  [CellDefinition(CellDataType.Number)]
  [Header(typeof(TeamRes), "NumberOfVictoryColumnName")]
  [Index(3)]
  public int? NumberOfVictory { get; set; }

  [CellDefinition(CellDataType.Boolean)]
  [Header(typeof(TeamRes), "IsActiveFlagColumnName")]
  [Index(4)]
  public bool? IsActiveFlag { get; set; }

  [CellDefinition(CellDataType.Boolean)]
  [Header(typeof(TeamRes), "SizeColumnName")]
  [Index(5)]
  public double? Size { get; set; }

  [CellDefinition(CellDataType.Number)]
  [Header(typeof(TeamRes), "SalaryColumnName")]
  [Index(5)]
  public decimal? Salary { get; set; }
}

What if I don't want to annotate my class with your annotations?

You can still use SimpleExcelExporter but you'll have a bit more code to write. Have a look at this example

What spreadsheet are supported ?

Before publishing a new version of SimpleExcelExporter to Nuget, we test the workbooks on:

  • Libre Office Calc (still/stable version)
  • Google Sheets
  • Excel 365 Windows (last stable version)
  • Excel 365 Mac OS (last stable version)
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

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.1 181 8/29/2023
1.3.0 151 8/28/2023
1.2.3 232 3/9/2023
1.2.2 231 3/8/2023
1.2.1 216 3/8/2023
1.1.0 404 2/20/2022