Seamlex.Utilities.ExcelToData
1.0.5
See the version list below for details.
dotnet add package Seamlex.Utilities.ExcelToData --version 1.0.5
NuGet\Install-Package Seamlex.Utilities.ExcelToData -Version 1.0.5
<PackageReference Include="Seamlex.Utilities.ExcelToData" Version="1.0.5" />
paket add Seamlex.Utilities.ExcelToData --version 1.0.5
#r "nuget: Seamlex.Utilities.ExcelToData, 1.0.5"
// Install Seamlex.Utilities.ExcelToData as a Cake Addin #addin nuget:?package=Seamlex.Utilities.ExcelToData&version=1.0.5 // Install Seamlex.Utilities.ExcelToData as a Cake Tool #tool nuget:?package=Seamlex.Utilities.ExcelToData&version=1.0.5
ExcelToData
Description
A general-purpose XLSX-to-.NET data conversion tool. Sample code to manipulate List<t>, byte[], and DataTable objects is below.
Project Details
This tool has been built to solve ad hoc problems that arise in life involving Excel documents. Microsoft Excel is the 'hammer and tongs of the Information Age'. Robust, repeatable, open-source, and memory-safe manipulation of XLSX files remains a goal even in a post-LLM world.
Usage
A compiled version of this sists on Nuget: https://www.nuget.org/packages/Seamlex.Utilities.ExcelToData
Installation
This is a class library that can be added to a project with: dotnet add package Seamlex.Utilities.ExcelToData
Sample code
#pragma warning disable CS1998
internal class Program
{
private static async Task Main(string[] args)
{
// set sample file names (MS Windows)
string output = @"c:\temp\test1.xlsx";
string output2 = @"c:\temp\test2.xlsx";
// instantiate this class
var xlsx = new Seamlex.Utilities.ExcelToData();
// create some demo data in a List<T>
var clients = new List<MyClass>(){
new MyClass() { IsValid = false, DollarAmount = 123.45, StartDate = DateTime.Now.AddDays(7), EndDate = DateTime.Now.AddMonths(3), FirstName = "Asha", LastName = "Albatross", MyProp = new ClassProp(){IsValid=true, DollarAmount=2.50} },
new MyClass() { IsValid = true, DollarAmount = 400.00, StartDate = DateTime.Now.AddDays(14), EndDate = DateTime.Now.AddMonths(4),FirstName = "Bianca", LastName = "Best", MyProp = new ClassProp(){IsValid=false, DollarAmount=0.50} },
new MyClass() { IsValid = false, DollarAmount = 100.00, StartDate = DateTime.Now.AddDays(21), EndDate = DateTime.Now.AddMonths(5), FirstName = "Carl", LastName = "Cranston", MyProp = new ClassProp(){IsValid=true, DollarAmount=1.50} }
};
// this changes default behaviour of the client which outputs as text to all fields
//xlsx.GetOptions().ColumnsToDateTime.Add("StartDate");
//xlsx.GetOptions().ColumnsToNumber.Add("DollarAmount");
// this creates an Excel file from a .NET List<T>
xlsx.ToExcelFile(clients, output);
// this displays the last error (if any)
if (xlsx.ErrorMessage != "")
Console.WriteLine(xlsx.ErrorMessage);
// this loads an Excel file into a System.Data.DataTable object
var dt = xlsx.ToDataTable(output);
// this saves it to a second file
xlsx.ToExcelFile(dt, output2);
// this reloads that second file into an in-memory byte array
byte[] file = xlsx.ToExcelBinary(output2);
// this takes the in-memory object and converts it to a List<T> then outputs
// to the console
var list2 = xlsx.ToListData<MyClass>(file);
foreach (var item in list2)
Console.WriteLine(
$"{item.FirstName} {item.LastName} {item.StartDate} {item.EndDate} {item.DollarAmount} {item.MyProp.DollarAmount} ");
return;
}
}
// demo class with a combination of fields and properties
public class MyClass {
public bool IsValid = false;
public double DollarAmount { get; set; }
public DateTime StartDate = DateTime.Now;
public DateTime? EndDate { get; set; }
public string FirstName = "";
public string LastName = "";
public ClassProp MyProp = new ClassProp();
}
public class ClassProp {
public bool IsValid = false;
public double DollarAmount { get; set; }
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net7.0
- DocumentFormat.OpenXml (>= 2.19.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.