SkillAgentSearch skills...

Table.lib

Simple c# (.NET 8) table library that renders any List<T> or Dictionary<TV, T> into a nicely formatted markdown, CSV, HTML, specflow or console table, allowing for extra formats. It also supports dynamic returns from Dapper as IEnumerable<IDictionary<string, object>> via DBTable object.

Install / Use

/learn @JordiCorbilla/Table.lib
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

table.lib

This is a versatile and user-friendly C# (.NET 8) table library that can quickly render any List<T> or Dictionary<TV, T> into a visually appealing markdown, CSV, HTML, SpecFlow, SQL-insert, or console table format, while providing flexibility for other formats as well. In addition, it also supports dynamic returns from Dapper as IEnumerable<IDictionary<string, object>> via DBTable object. Whether you need to format data for documentation, testing, or display purposes, this library makes it easy to do so in a variety of formats, with just a few lines of code.

Installation

via nuget package -> https://www.nuget.org/packages/table.lib/

dotnet add package table.lib --version 1.13.0

Markdown format in the console output

To make it easier to share, table.lib outputs the console output as markdown friendly. Note that there is a specific markdown output so the text justification can happen as per markdown specification.

Table<TestClass>.Add(list).ToConsole();
| Field1 | Field2               | Field3        | Field4 | Field5      | Field6 |
| ------ | -------------------- | ------------- | ------ | ----------- | ------ |
| 321121 | Hi 312321            | 2,121.32      | True   | 01-Jan-1970 | 34.43  |
| 32321  | Hi long text         | 21,111,111.32 | True   | 01-Jan-1970 | 34.43  |
| 321    | Hi longer text       | 2,121.32      | True   | 01-Jan-1970 | 34.43  |
| 13     | Hi very long text    | 21,111,121.32 | True   | 01-Jan-1970 | 34.43  |
| 13     | Hi very, long text   | 21,111,121.32 | True   | 01-Jan-1970 | 34.43  |
| 13     | Hi "very" long  text | 21,111,121.32 | True   | 01-Jan-1970 | 34.43  |

| Field1 | Field2 | Field3 | Field4 | Field5 | Field6 | | ------ | -------------------- | ------------- | ------ | ----------- | ------ | | 321121 | Hi 312321 | 2,121.32 | True | 01-Jan-1970 | 34.43 | | 32321 | Hi long text | 21,111,111.32 | True | 01-Jan-1970 | 34.43 | | 321 | Hi longer text | 2,121.32 | True | 01-Jan-1970 | 34.43 | | 13 | Hi very long text | 21,111,121.32 | True | 01-Jan-1970 | 34.43 | | 13 | Hi very, long text | 21,111,121.32 | True | 01-Jan-1970 | 34.43 | | 13 | Hi "very" long text | 21,111,121.32 | True | 01-Jan-1970 | 34.43 |

Considerations:

  • Any CRLF will be automatically transformed into a space for an easy representation of the output

Dynamic Fields

If the List contains another collection of <strings>, the library is able to scan those and build the resultant dataset giving them a column name called DynamicN:

var test = new List<IEnumerable<string>>
{
    new List<string>() {"AAA", "BBB", "CCC"},
    new List<string>() {"AAA", "BBB", "CCC"},
    new List<string>() {"AAA", "BBB", "CCC"},
    new List<string>() {"AAA", "BBB", "CCC"}
};

Table<IEnumerable<string>>.Add(test).ToConsole();
| Capacity | Count | Dynamic0 | Dynamic1 | Dynamic2 |
| -------- | ----- | -------- | -------- | -------- |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |

| Capacity | Count | Dynamic0 | Dynamic1 | Dynamic2 | | -------- | ----- | -------- | -------- | -------- | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC |

Column Name change

If the name of the column is not of your liking, you can change it via OverrideColumnsNames and provide your preferred name. Note that this will also alter the column width to allow for more room if the new name is larger than the previous one.

Table<IEnumerable<string>>.Add(test)
    .OverrideColumnsNames(new Dictionary<string, string> {{"Dynamic0","ColumnA"}})
    .ToConsole();
| Capacity | Count | ColumnA  | Dynamic1 | Dynamic2 |
| -------- | ----- | -------- | -------- | -------- |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |
| 4        | 3     | AAA      | BBB      | CCC      |

| Capacity | Count | ColumnA | Dynamic1 | Dynamic2 | | -------- | ----- | -------- | -------- | -------- | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC | | 4 | 3 | AAA | BBB | CCC |

Column filtering

You don't want to show all the columns? Easy, just use the FilterColumns property and define the action to perform FilterAction.Include or FilterAction.Exclude:

By default it will use the FilterAction.Exclude functionality:

Table<IEnumerable<string>>.Add(test)
    .OverrideColumnsNames(new Dictionary<string, string> { { "Dynamic0", "ColumnA" } })
    .FilterColumns(new []{ "Capacity", "Count" })
    .ToConsole();
| ColumnA  | Dynamic1 | Dynamic2 |
| -------- | -------- | -------- |
| AAA      | BBB      | CCC      |
| AAA      | BBB      | CCC      |
| AAA      | BBB      | CCC      |
| AAA      | BBB      | CCC      |

| ColumnA | Dynamic1 | Dynamic2 | | -------- | -------- | -------- | | AAA | BBB | CCC | | AAA | BBB | CCC | | AAA | BBB | CCC | | AAA | BBB | CCC |

Table<IEnumerable<string>>.Add(test)
    .OverrideColumnsNames(new Dictionary<string, string> { { "Dynamic0", "ColumnA" } })
    .FilterColumns(new []{ "Dynamic0" }, FilterActions.Include)
    .ToConsole();
| Dynamic0 |
| -------- |
| AAA      |
| AAA      |
| AAA      |
| AAA      |

Row Highlighter

With a simple operation, we can now highlight the entire content of the table using the code below:

Table<IEnumerable<string>>.Add(GetStringMatrix())
    .FilterColumns(new[] { "Dynamic0", "Dynamic1" }, FilterAction.Include)
    .HighlightRows(ConsoleColor.Red, ConsoleColor.White)
    .ToConsole();

**Note that this option will highlight all the rows

image

Field Highlighter

You need more control over the field you want to highlight? then use the highlight operator:

Table<TestClass>.Add(GetSampleOutput())
    .HighlightValue(new HighlightOperator
        {Field = "Field3", Type = HighlightType.Decimal, DecimalValue = 2121.32m})
    .ToConsole();

**Note that this option will highlight one specific cell and it will use two colors, one for = and one for <>

image

Column Justification

You need one of the columns, right aligned or centered? Use the column justification option.

Table<IEnumerable<string>>.Add(test)
    .OverrideColumnsNames(new Dictionary<string, string>
    {
        { "Dynamic0", "A" },
        { "Dynamic1", "B" },
        { "Dynamic2", "C" }
    })
    .FilterOutColumns(new[] { "Capacity", "Count" })
    .ColumnContentTextJustification(new Dictionary<string, TextJustification>
    {
        { "Dynamic0", TextJustification.Right }, 
        { "Dynamic1", TextJustification.Centered }
    })
    .ToConsole();

Note that this will only affect markdown, console and html outputs and only their data. Columns labels will remain left aligned.

|    A     |    B     |    C     |
| -------- | -------- | -------- |
|      AAA |   BBB    | CCC      |
|      AAA |   BBB    | CCC      |
|      AAA |   BBB    | CCC      |
|      AAA |   BBB    | CCC      |

| ColumnA | Dynamic1 | Dynamic2 | | -------: | -------- | -------- | | AAA | BBB | CCC | | AAA | BBB | CCC | | AAA | BBB | CCC | | AAA | BBB | CCC |

HTML Output

Transform your output into a nicely formatted HTML table

Table<IEnumerable<string>>.Add(test)
    .OverrideColumnsNames(new Dictionary<string, string> { { "Dynamic0", "ColumnA" } })
    .FilterColumns(new []{ "Capacity", "Count" })
    .ToHtml(@"C:\temp\test.html");

Table<TestClass>.Add(list)
    .ToHtml(@"C:\temp\test-list.html");

Sample generated code:

<table style="border-collapse: collapse; width: 100%;">
<tr>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field1</th>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field2</th>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field3</th>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field4</th>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field5</th>
<th style="text-align: center; background-color: #052a3d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Field6</th>
</tr>
<tr>
<td style="text-align: right; color: black; background-color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">321121</td>
<td style="text-align: right; color: black; background-color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;">Hi 312321</td>
<td style="text-align: right; color: black; background-color: white;padding: 4px;border: 1px solid #dddddd; font-f
View on GitHub
GitHub Stars23
CategoryProduct
Updated7mo ago
Forks3

Languages

C#

Security Score

87/100

Audited on Aug 22, 2025

No findings