A .NET Standard 2.1 library that adapts CSV data read by CsvHelper to a format that can be consumed by TextTabulator.
$ dotnet add package Jwelsch.TextTabulator.Adapters.CsvHelperThis is an auxillary library for TextTabulator that provides an integration with the popular CsvHelper library that allows TextTabulator to consume CSV data.
First, install the TextTabulator main package and then this one.
Install the TextTabulator.Adapters.CsvHelper Nuget package in your project.
nuget install JWelsch.TextTabulator.Adapters.CsvHelper
You can call the code like this:
using CsvHelper;
using System.IO;
using TextTabulator;
using TextTabulator.Adapters.CsvHelper;
var csvData =
@"Name,Weight (tons),Diet,Extinction
Tyrannosaurus Rex,6.7,Carnivore,66 mya
Triceratops,8,Herbivore,66 mya
Apatosaurus,33,Herbivore,147 mya
Archaeopteryx,0.001,Omnivore,147 mya
Anklyosaurus,4.8,Herbivore,66 mya
Stegosaurus,3.8,Herbivore,147 mya
Hadrosaurus,3,Herbivore,66 mya
";
using var textReader = new StringReader(csvData);
using var csvReader = new CsvReader(textReader, CultureInfo.InvariantCulture);
var csvAdapter = new CsvHelperTabulatorAdapter(csvReader);
var tabulator = new Tabulator();
var table = tabulator.Tabulate(csvAdapter);
Console.WriteLine(table);
This will produce the output:
------------------------------------------------------
|Name |Weight (tons)|Diet |Extinction|
|-----------------+-------------+---------+----------|
|Tyrannosaurus Rex|6.7 |Carnivore|66 mya |
|-----------------+-------------+---------+----------|
|Triceratops |8 |Herbivore|66 mya |
|-----------------+-------------+---------+----------|
|Apatosaurus |33 |Herbivore|147 mya |
|-----------------+-------------+---------+----------|
|Archaeopteryx |0.001 |Omnivore |147 mya |
|-----------------+-------------+---------+----------|
|Anklyosaurus |4.8 |Herbivore|66 mya |
|-----------------+-------------+---------+----------|
|Stegosaurus |3.8 |Herbivore|147 mya |
|-----------------+-------------+---------+----------|
|Hadrosaurus |3 |Herbivore|66 mya |
------------------------------------------------------
Follow the link for the full public API documentation.