FreeDataExports 1.1.12
dotnet add package FreeDataExports --version 1.1.12
NuGet\Install-Package FreeDataExports -Version 1.1.12
<PackageReference Include="FreeDataExports" Version="1.1.12" />
paket add FreeDataExports --version 1.1.12
#r "nuget: FreeDataExports, 1.1.12"
// Install FreeDataExports as a Cake Addin #addin nuget:?package=FreeDataExports&version=1.1.12 // Install FreeDataExports as a Cake Tool #tool nuget:?package=FreeDataExports&version=1.1.12
Free Data Exports (.NET)
Author: Ryan Kueter
Updated: December, 2024
About
Free Data Exports is a free .NET library, available from the NuGet Package Manager, that provides a simple and quick way to export data to a spreadsheet.
Supported file types:
- Office Open XML Spreadsheet (.xlsx) v2019
- Open Document File (ODF) Spreadsheet (.ods) v1.3
- Comma-separated Values (.csv)
Version Support:
- .NET 6 - .NET 9
- .NET Standard 2.0
- Core 2 - 3.1
- Framework 4.6.1 - 4.8
- Mono 5.4, 6.4
- Xamarin.iOS 10.14, 12.16
- Xamarin.Android 8.0, 10.0
- Universal Windows Platform 10.0.16299
- Unity 2018.1
- https://dotnet.microsoft.com/platform/dotnet-standard#versions
Initialization
Free Data Exports provides an interface that allows the developer to reduce code duplication when creating a spreadsheet in both formats. However, be aware that the values for tab color or column width are different when creating an .xlsx file or an .ods file.
// Namespace
using FreeDataExports;
// Create a new workbook
IDataWorkbook workbook = new DataExport().CreateXLSX2019();
IDataWorkbook workbook = new DataExport().CreateODSv1_3();
How to Create an XLSX (2019) File
An example of how to create a new .xlsx workbook in C#:
// Namespace
using FreeDataExports;
// Create a new workbook
var workbook = new DataExport().CreateXLSX2019();
// Optional - Add some metadata
workbook.CreatedBy = "Jane Doe";
// Optional - Change the font size
workbook.FontSize = 11;
// Create worksheets
var orders = workbook.AddWorksheet("Orders");
var inventory = workbook.AddWorksheet("Inventory");
// Add column titles
orders.AddRow()
.AddCell("OrderId", DataType.String)
.AddCell("Item", DataType.String)
.AddCell("Units", DataType.String)
.AddCell("Price", DataType.String)
.AddCell("OrderDate", DataType.String)
.AddCell("SalesAssoc", DataType.String)
.AddCell("Delivered", DataType.String);
// Add data
foreach (var o in Orders)
{
orders.AddRow()
.AddCell(o.OrderId, DataType.Number)
.AddCell(o.Item, DataType.String)
.AddCell(o.Units, DataType.Number)
.AddCell(o.Price, DataType.Currency)
.AddCell(o.OrderDate, DataType.LongDate)
.AddCell(o.SalesAssociate, DataType.String)
.AddCell(o.Delivered, DataType.Boolean);
}
// Add column titles
inventory.AddRow()
.AddCell("ItemId", DataType.String)
.AddCell("Item", DataType.String)
.AddCell("Number", DataType.String)
.AddCell("Price", DataType.String);
// Add data
foreach (var i in Inventory)
{
inventory.AddRow()
.AddCell(i.ItemId, DataType.Number)
.AddCell(i.Item, DataType.String)
.AddCell(i.Number, DataType.Number)
.AddCell(i.Price, DataType.Currency);
}
// Optional - Add a tab color in RGB
orders.TabColor = "0000FF00"; // Green
inventory.TabColor = "000000FF"; // Blue
// Optional - Add column widths, based on character widths
orders.ColumnWidths("10", "10", "5", "10", "28.5", "15", "10");
inventory.ColumnWidths("10", "10", "10", "10");
// Optional - Reformat a data type
workbook.Format(DataType.DateTime24, @"m/d/yy\ h:mm;@");
// Optional - Add a worksheet to display data type conversion errors, only if they occur
workbook.AddErrorsWorksheet();
// Optional - Get the error manually
workbook.GetErrors();
// Synchronous GetBytes method
workbook.GetBytes();
// Asynchronous GetBytes method
await workbook.GetBytesAsync();
// Synchronous save method
workbook.Save(path);
// Asynchronous save method
await workbook.SaveAsync(path);
How to Create an ODS (1.3) File
The following code block is an example of how to create a new .ods workbook in C#.
// Namespaces
using FreeDataExports;
// Create a new workbook
var workbook = new DataExport().CreateODSv1_3();
// Optional - Add some metadata
workbook.CreatedBy = "Jane Doe";
// Optional - Change the font size
workbook.FontSize = 11;
// Create worksheets
var orders = workbook.AddWorksheet("Orders");
var inventory = workbook.AddWorksheet("Inventory");
// Add column titles
orders.AddRow()
.AddCell("OrderId", DataType.String)
.AddCell("Item", DataType.String)
.AddCell("Units", DataType.String)
.AddCell("Price", DataType.String)
.AddCell("OrderDate", DataType.String)
.AddCell("SalesAssoc", DataType.String)
.AddCell("Delivered", DataType.String);
// Add data
foreach (var o in Orders)
{
orders.AddRow()
.AddCell(o.OrderId, DataType.Number)
.AddCell(o.Item, DataType.String)
.AddCell(o.Units, DataType.Number)
.AddCell(o.Price, DataType.Currency)
.AddCell(o.OrderDate, DataType.LongDate)
.AddCell(o.SalesAssociate, DataType.String)
.AddCell(o.Delivered, DataType.Boolean);
}
// Add column titles
inventory.AddRow()
.AddCell("ItemId", DataType.String)
.AddCell("Item", DataType.String)
.AddCell("Number", DataType.String)
.AddCell("Price", DataType.String);
// Add data
foreach (var i in Inventory)
{
inventory.AddRow()
.AddCell(i.ItemId, DataType.Number)
.AddCell(i.Item, DataType.String)
.AddCell(i.Number, DataType.Number)
.AddCell(i.Price, DataType.Currency);
}
// Optional - Format the tab color in Hexadecimal
orders.TabColor = "#00FF00"; // Green
inventory.TabColor = "#0000FF"; // Blue
// Optional - Add column widths in inches or centimeters (Specify the unit of measure)
orders.ColumnWidths(".8in", "1in", ".5in", "1in", "1.5in", "1in", "1in");
inventory.ColumnWidths(".8in", "1in", ".8in", "1in");
// Optional - Reformat the datatypes
workbook.Format(DataType.Decimal, "decimals=8");
workbook.Format(DataType.Currency, "symbol=$,language=en,country=US,decimals=2");
// Optional - Add a worksheet to display data type conversion errors, only if they occur
workbook.AddErrorsWorksheet();
// Optional - Get the error manually
workbook.GetErrors();
// Synchronous GetBytes method
workbook.GetBytes();
// Asynchronous GetBytes method
await workbook.GetBytesAsync();
// Synchronous save method
workbook.Save(path);
// Asynchronous save method
await workbook.SaveAsync(path);
How to Create a CSV File
An example of how to create a new .csv file in C#:
// Namespace
using FreeDataExports;
// Create a new csv file
var csv = new DataExport().CreateCsv();
// Add a header row
csv.AddRow("OrderId", "Item", "Units", "Price", "OrderDate", "SalesAssoc", "Delivered");
// Add some data
foreach (var o in Orders)
{
csv.AddRow(o.OrderId, o.Item, o.Units, o.Price, o.OrderDate, o.SalesAssociate, o.Delivered);
}
// Synchronous GetBytes method
csv.GetBytes();
// Asynchronous GetBytes method
await csv.GetBytesAsync();
// Synchronous save method
csv.Save(path);
// Asynchronous save method
await csv.SaveAsync(path);
Formating Options
XLSX Formatting Strings
The following formatting strings are stored in the document and allow you to customize the format of numeric data types. Please note that many of the .xlsx formatting strings were written in C# and are string literals.
- Currency:
@"""$""#,##0.00"
- Percent:
@"0.00%"
- DateTime:
@"[$-409]m/d/yyyy\ h:mm:ss\ AM/PM;@"
- Decimal:
"0.0000"
- Date:
@"m/d/yyyy"
- Time:
@"h:mm\ AM/PM"
- LongDate:
@"[$-F800]dddd\,\ mmmm\ dd\,\ yyyy"
- DateTime24:
@"m/d/yyyy\ h:mm:ss;@"
- Time24:
@"h:mm:ss;@"
ODS Formatting Strings
ODS files do not contain formatting strings like those above. So, the following formatting options are provided:
- Currency:
"symbol=$,language=en,country=US,decimals=2"
- Alternatively:
"decimals=2"
- Alternatively:
- Decimal:
"decimals=4"
Data Types
The library currently contains the following built in datatypes, which can be customized using the formating options:
- String
- Number
- Currency
- Percent
- DateTime
- Decimal
- Date
- Time
- LongDate
- DateTime24
- Time24
- Boolean
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 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. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
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.1.12 | 101 | 12/5/2024 |
1.1.11 | 191 | 9/18/2024 |
1.1.10 | 116 | 9/17/2024 |
1.1.9 | 457 | 11/26/2023 |
1.1.8 | 137 | 11/25/2023 |
1.1.7 | 419 | 11/26/2022 |
1.1.6 | 344 | 11/26/2022 |
1.1.5 | 412 | 9/12/2022 |
1.1.4 | 429 | 8/15/2022 |
1.1.3 | 1,420 | 2/5/2022 |
1.1.2 | 453 | 2/5/2022 |
1.0.24 | 443 | 1/26/2022 |
1.0.23 | 440 | 1/21/2022 |
1.0.22 | 282 | 12/24/2021 |
1.0.21 | 271 | 12/24/2021 |
1.0.20 | 333 | 12/16/2021 |
1.0.19 | 292 | 12/16/2021 |
1.0.18 | 305 | 10/15/2021 |
1.0.17 | 370 | 10/15/2021 |
1.0.16 | 379 | 10/15/2021 |
1.0.15 | 378 | 10/15/2021 |
1.0.14 | 375 | 10/4/2021 |
1.0.13 | 342 | 5/20/2021 |
1.0.12 | 297 | 5/5/2021 |
1.0.11 | 390 | 5/1/2021 |
Updated documentation.