FreeDataExports 1.0.19

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

// Install FreeDataExports as a Cake Tool
#tool nuget:?package=FreeDataExports&version=1.0.19                

Free Data Exports (.NET)

Author: Ryan Kueter
Updated: December, 2021

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)
Targets:
  • .NET 6
  • .NET Standard 2.1
Version Support

How to Create an XLSX (2019) File

An example of how to create a new .xlsx workbook in C#:

// Namespaces
using FreeDataExports.Spreadsheets;
using FreeDataExports.Spreadsheets.XL2019;

// Create a new workbook
var workbook = new XLSX2019();

// 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 some data to the worksheets
orders.AddRow(
	orders.AddCell("OrderId", DataType.String),
	orders.AddCell("Item", DataType.String),
	orders.AddCell("Units", DataType.String),
	orders.AddCell("Price", DataType.String),
	orders.AddCell("OrderDate", DataType.String),
	orders.AddCell("SalesAssoc", DataType.String),
	orders.AddCell("Delivered", DataType.String));

foreach (var o in Orders)
{
	orders.AddRow(
		orders.AddCell(o.OrderId, DataType.Number),
		orders.AddCell(o.Item, DataType.String),
		orders.AddCell(o.Units, DataType.Number),
		orders.AddCell(o.Price, DataType.Currency),
		orders.AddCell(o.OrderDate, DataType.LongDate),
		orders.AddCell(o.SalesAssociate, DataType.String),
		orders.AddCell(o.Delivered, DataType.Boolean));
}

inventory.AddRow(
	inventory.AddCell("ItemId", DataType.String),
	inventory.AddCell("Item", DataType.String),
	inventory.AddCell("Number", DataType.String),
	inventory.AddCell("Price", DataType.String));

foreach (var i in Inventory)
{
	inventory.AddRow(
		inventory.AddCell(i.ItemId, DataType.Number),
		inventory.AddCell(i.Item, DataType.String),
		inventory.AddCell(i.Number, DataType.Number),
		inventory.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.Spreadsheets;
using FreeDataExports.Spreadsheets.Ods1_3;

// Create a new workbook
var workbook = new ODSv1_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 some data to the worksheets
orders.AddRow(
	orders.AddCell("OrderId", DataType.String),
	orders.AddCell("Item", DataType.String),
	orders.AddCell("Units", DataType.String),
	orders.AddCell("Price", DataType.String),
	orders.AddCell("OrderDate", DataType.String),
	orders.AddCell("SalesAssoc", DataType.String),
	orders.AddCell("Delivered", DataType.String));

foreach (var o in Orders)
{
	orders.AddRow(
		orders.AddCell(o.OrderId, DataType.Number),
		orders.AddCell(o.Item, DataType.String),
		orders.AddCell(o.Units, DataType.Number),
		orders.AddCell(o.Price, DataType.Currency),
		orders.AddCell(o.OrderDate, DataType.LongDate),
		orders.AddCell(o.SalesAssociate, DataType.String),
		orders.AddCell(o.Delivered, DataType.Boolean));
}

inventory.AddRow(
	inventory.AddCell("ItemId", DataType.String),
	inventory.AddCell("Item", DataType.String),
	inventory.AddCell("Number", DataType.String),
	inventory.AddCell("Price", DataType.String));

foreach (var i in Inventory)
{
	inventory.AddRow(
		inventory.AddCell(i.ItemId, DataType.Number),
		inventory.AddCell(i.Item, DataType.String),
		inventory.AddCell(i.Number, DataType.Number),
		inventory.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.Delimited;

// Create a new csv file
var csv = new Csv();

// 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"
  • 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 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 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.
  • .NETStandard 2.1

    • No dependencies.
  • net6.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.11 129 9/18/2024
1.1.10 107 9/17/2024
1.1.9 419 11/26/2023
1.1.8 129 11/25/2023
1.1.7 413 11/26/2022
1.1.6 340 11/26/2022
1.1.5 407 9/12/2022
1.1.4 425 8/15/2022
1.1.3 1,267 2/5/2022
1.1.2 448 2/5/2022
1.0.24 438 1/26/2022
1.0.23 435 1/21/2022
1.0.22 277 12/24/2021
1.0.21 266 12/24/2021
1.0.20 329 12/16/2021
1.0.19 287 12/16/2021
1.0.18 300 10/15/2021
1.0.17 365 10/15/2021
1.0.16 374 10/15/2021
1.0.15 373 10/15/2021
1.0.14 370 10/4/2021
1.0.13 337 5/20/2021
1.0.12 292 5/5/2021
1.0.11 385 5/1/2021

A NuGet package for targeting multiple frameworks.