Skip to content
A fluent library to print out a nicely formatted table in a console application C#
C#
Branch: master
Clone or download
Latest commit e9e116a Jul 30, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Src update icon path Dec 25, 2018
wiki/Images update demo image Dec 1, 2017
.gitignore Add support for generic lists. Dec 24, 2018
ConsoleTableExtSolution.sln migrate to .net standard 2.0 Feb 13, 2018
LICENSE Initial commit Nov 23, 2017
README.md Update README.md Jul 30, 2019

README.md

ConsoleTableExt Build status

A library to print out a nicely formatted table in a console application C#

Nuget

Install-Package ConsoleTableExt

Demo

https://github.com/minhhungit/ConsoleTableExt/tree/master/Src/ConsoleTableApp

How to use:

From [DataTable] type and Default format:

ConsoleTableBuilder
   .From(GetSampleTableData())
   .ExportAndWriteLine();

From [DataTable] type and Minimal format:

ConsoleTableBuilder
   .From(GetSampleTableData())
   .WithFormat(ConsoleTableBuilderFormat.Minimal)
   .ExportAndWriteLine();

From [List] type and Alternative format:

ConsoleTableBuilder
   .From(GetSampleListData())
   .WithFormat(ConsoleTableBuilderFormat.Alternative)
   .ExportAndWriteLine();

From [List] type and MarkDown format w/ custom column name:

ConsoleTableBuilder
   .From(GetSampleListData())
   .WithFormat(ConsoleTableBuilderFormat.MarkDown)
   .WithColumn(new List<string>{ "N A M E" , "[Position]", "Office", "<Age>", "Something else I don't care"})
   .ExportAndWriteLine();

Custom:

var arrayBuilder = ConsoleTableBuilder.From(new List<object[]>
{
    new object[] {"luong", "son", "ba", null, "phim", null, null, null, 2, null},
    new object[] {"chuc", "anh", "dai", "nhac", null, null, null }
});


arrayBuilder
   .AddRow(new List<object> {1, "this", "is", "new", "row", "use", "<List>", null, null, null})
   .AddRow(new object[] {"2", "new row", "use", "array[] values", null, null})
   .WithOptions(new ConsoleTableBuilderOption
   {
       MetaRowPosition = MetaRowPosition.Bottom,
       MetaRowFormat = "\n=> This table has {3} rows and {2} columns\n=> [{0}] - [test value {1}]",
       MetaRowParams = new object[]
       {
           "test value 1",
           2,
           AppConstants.MetaRow.COLUMN_COUNT,
           AppConstants.MetaRow.ROW_COUNT 
       },
       TrimColumn = true,
       Delimiter = "¡",
       DividerString = "»",
   })
   .WithFormat(ConsoleTableBuilderFormat.MarkDown)
   .WithColumn(new List<string> {"THIS", "IS", "ADVANCED", "OPTIONS"})
   .ExportAndWriteLine();

Sample data:

static DataTable SampleTableData()
{
   DataTable table = new DataTable();
   table.Columns.Add("Name", typeof(string));
   table.Columns.Add("Position", typeof(string));
   table.Columns.Add("Office", typeof(string));
   table.Columns.Add("Age", typeof(int));
   table.Columns.Add("Start Date", typeof(DateTime));

   table.Rows.Add("Airi Satou", "Accountant", "Tokyo", 33, new DateTime(2017, 05, 09));
   table.Rows.Add("Angelica Ramos", "Chief Executive Officer (CEO)", "New York", 47, new DateTime(2017, 01, 12));
   table.Rows.Add("Ashton Cox", "Junior Technical Author", "London", 46, new DateTime(2017, 04, 02));
   table.Rows.Add("Bradley Greer", "Software Engineer", "San Francisco", 28, new DateTime(2017, 11, 15));

   return table;
}

static List<List<object>> SampleListData = new List<List<object>>
{
   new List<object>{ "Sakura Yamamoto", "Support Engineer", "London", 46},
   new List<object>{ "Serge Baldwin", "Data Coordinator", "San Francisco", 28, "something else" },
   new List<object>{ "Shad Decker", "Regional Director", "Edinburgh"},
};

Inspired by

You can’t perform that action at this time.