robbiblubber.org
EN
Projects
Collection.NETMIT

Data.Util.NET.

Robbiblubber.Data.Util.NET

Prepare data for its next step: export typed collections as CSV or Excel, generate SQL INSERT statements from query results, and read OData services page by page. Four libraries that can be added individually to your .NET applications.

.NET 8.NET 10

Libraries & extensions

4

The libraries are available as separate NuGet packages. Install the building blocks your project needs.

Library

Robbiblubber.Data.Util.CSV

CSV export for IEnumerable<T>: define columns and headers explicitly, select values through functions, and customise the output format.

For .NET applicationsTarget frameworks: net8.0 / net10.0

What’s inside

  • CsvExport<T> works with your data types; DataField<T> defines column order, headers, and value selection.
  • Configure field and decimal separators, quotes, line endings, and file encoding.
  • CsvOptions.GERMAN provides semicolon and decimal-comma defaults; header rows are optional.
  • Write to a file, stream, TextWriter, or string using synchronous or asynchronous methods.
A small starting point C#
using Robbiblubber.Data.Util.CSV;

CsvExport<Product> export = new(
    fieldDefinition:
    [
        new CsvExport.DataField<Product>("Name", p => p.Name),
        new CsvExport.DataField<Product>("Price", p => p.Price)
    ],
    csvOptions: CsvOptions.GERMAN.Clone());

await export.WriteToFileAsync("products.csv", [new Product("Notebook", 4.50m)]);

record Product(string Name, decimal Price);

Two explicit columns, a header row, and German number formatting. Customise a copy of the options.

Installation
dotnet add package Robbiblubber.Data.Util.CSV
Library

Robbiblubber.Data.Util.Excel

Create Excel files from typed data: define columns, a worksheet, and cell formatting, then write the result as an XLSX file or stream.

Uses ClosedXML; no installed Excel application requiredTarget frameworks: net8.0 / net10.0

What’s inside

  • ExcelExport<T> and DataField<T> map your data types to column headers and value functions.
  • Configure worksheet names, column widths, and optional headers; write numbers, dates, and other values as corresponding cell values.
  • Colours, borders, bold, and italic styles for headers and data cells; separate formats for the first and last data rows.
  • CustomizeCell supports additional ClosedXML customisation per cell; output to files and streams.
A small starting point C#
using Robbiblubber.Data.Util.Excel;

ExcelExport<Product> export = new(
    fieldDefinition:
    [
        new ExcelExport.DataField<Product>("Name", p => p.Name),
        new ExcelExport.DataField<Product>("Price", p => p.Price)
    ],
    columnWidths: [28d, 14d], worksheetName: "Products");

export.WriteToFile("products.xlsx", [new Product("Notebook", 4.50m)]);

record Product(string Name, decimal Price);

Creates one worksheet with two columns. Supply one column width per defined column.

Installation
dotnet add package Robbiblubber.Data.Util.Excel
Library

Robbiblubber.Data.Util.Export

Export SQL query results as INSERT statements. SqlExport reads through an existing ADO.NET connection and generates a script for the specified target table.

Open IDbConnection and an appropriate ADO.NET providerTarget frameworks: net8.0 / net10.0

What’s inside

  • Your SELECT query determines which rows and columns are exported.
  • Each result row becomes an INSERT statement using the result’s column names.
  • Handles strings containing apostrophes, NULL, date/time values, and culture-independent decimal numbers.
  • Statements exposes individual statements; ToString() returns the combined script. Check SQL syntax against the target system.
A small starting point C#
using System.Data;
using Robbiblubber.Data.Util.Export;

static string ExportProducts(IDbConnection connection)
{
    using SqlExport export = new(connection, "Products_Copy",
        "SELECT Id, Name, Price FROM Products");
    export.Execute();
    return export.ToString();
}

The connection must already be open. Execute() reads the source and generates the script; it does not execute the INSERT statements.

Installation
dotnet add package Robbiblubber.Data.Util.Export
Library

Robbiblubber.Data.Util.OData

Read OData JSON using an existing HttpClient: request individual pages or iterate records with await foreach, following OData continuation links.

OData JSON endpoint with a value array; configure HttpClient for the serviceTarget frameworks: net8.0 / net10.0

What’s inside

  • NextPageAsync returns a page as a JsonObject; NextValuesAsync returns its value array.
  • IAsyncEnumerable<JsonObject> enables await foreach over records across multiple pages.
  • @odata.nextLink drives pagination, with support for relative and absolute HTTP(S) continuation links.
  • OnRequest supports custom HTTP headers; CancellationToken supports cancellation, and Rewind() resets the reader.
A small starting point C#
using Robbiblubber.Data.Util.OData;

using HttpClient client = new();
ODataReader reader = new(client,
    "https://service.example.org/odata/Products?$select=Id,Name");

await foreach (var product in reader)
{
    Console.WriteLine(product["Name"]);
}

Replace the example URL and configure HttpClient for authentication when required. The reader returns JsonObject records.

Installation
dotnet add package Robbiblubber.Data.Util.OData

The .NET libraries are distributed through NuGet. Tools and libraries remain grouped in their suites and collections.

View all projects