SimpleExcelExporter 1.4.1-alpha.1
See the version list below for details.
dotnet add package SimpleExcelExporter --version 1.4.1-alpha.1
NuGet\Install-Package SimpleExcelExporter -Version 1.4.1-alpha.1
<PackageReference Include="SimpleExcelExporter" Version="1.4.1-alpha.1" />
paket add SimpleExcelExporter --version 1.4.1-alpha.1
#r "nuget: SimpleExcelExporter, 1.4.1-alpha.1"
// Install SimpleExcelExporter as a Cake Addin #addin nuget:?package=SimpleExcelExporter&version=1.4.1-alpha.1&prerelease // Install SimpleExcelExporter as a Cake Tool #tool nuget:?package=SimpleExcelExporter&version=1.4.1-alpha.1&prerelease
SimpleExcelExporter
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?
- 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>();
}
}
- 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 ?
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
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 | Versions 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. |
-
.NETStandard 2.1
- DocumentFormat.OpenXml (>= 3.0.2)
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.4.3 | 68 | 9/23/2024 |
1.4.3-alpha | 55 | 9/23/2024 |
1.4.2 | 98 | 8/27/2024 |
1.4.2-alpha.1 | 49 | 8/27/2024 |
1.4.2-alpha | 102 | 8/21/2024 |
1.4.1 | 106 | 6/7/2024 |
1.4.1-alpha.2 | 49 | 6/7/2024 |
1.4.1-alpha.1 | 55 | 6/6/2024 |
1.4.1-alpha | 89 | 6/6/2024 |
1.4.0 | 357 | 6/3/2024 |
1.4.0-alpha | 88 | 6/3/2024 |
1.3.1 | 209 | 8/29/2023 |
1.3.0 | 182 | 8/28/2023 |
1.2.3 | 261 | 3/9/2023 |
1.2.2 | 253 | 3/8/2023 |
1.2.1 | 242 | 3/8/2023 |
1.1.0 | 425 | 2/20/2022 |