Overview
Welcome to ConsoleTables, a .NET library for effortlessly printing strongly-typed objects or dynamic data to your console in a clean, readable, tabular format. If you've ever wanted to output flat-structured POCOs to the console for debugging, reporting, or building CLI tools, this library is for you.
It provides a simple, fluent API to create, populate, and customize tables with minimal code.
Key Features
- Simple, Fluent API: Chain methods like
AddRow()
andConfigure()
for easy table construction. - Multiple Data Sources: Automatically generate tables from
IEnumerable<T>
,DataTable
,Dictionary
, or a 2DObject[][]
array. - Customizable Formatting: Control column alignment, choose from multiple table border styles, and toggle the display of the row count.
- Smart Width Handling: Supports word wrapping for long text and correctly handles Unicode characters to maintain table alignment.
- Multiple Output Targets: Write to the console or any
TextWriter
for flexibility.
A Quick Example
Here's how simple it is to get started. Let's create a table manually and also generate one from a list of objects.
using ConsoleTables;
using System;
using System.Linq;
public class Something
{
public string Id { get; } = Guid.NewGuid().ToString("N");
public string Name { get; private set; } = "Khalid Abuhkameh";
public DateTime Date { get; } = DateTime.UtcNow;
}
class Program
{
static void Main(string[] args)
{
// Manually create a table
var table = new ConsoleTable("one", "two", "three");
table.AddRow(1, 2, 3)
.AddRow("this line should be longer", "yes it is", "oh");
table.Write();
Console.WriteLine();
// Create a table from a collection of objects
var rows = Enumerable.Repeat(new Something(), 2);
ConsoleTable
.From<Something>(rows)
.Configure(o => o.NumberAlignment = Alignment.Right)
.Write(Format.Alternative);
Console.ReadKey();
}
}
Console Output
This code produces the following beautifully formatted output in the console:
Ready to get started? Head over to the Installation page to add ConsoleTables to your project, then follow the Quick Start guide.