When you need to display data in rows and columns, use Table.
Create a Table
To create a table, add columns then rows.
var table = new Table();
table.AddColumn("Name");
table.AddColumn("Department");
table.AddColumn("Sales");
table.AddRow("Alice", "North", "$12,400");
table.AddRow("Bob", "South", "$8,750");
table.AddRow("Carol", "West", "$15,200");
AnsiConsole.Write(table);
Style the Borders
If you want rounded borders, call .RoundedBorder().
var table = new Table()
.RoundedBorder()
.BorderColor(Color.Grey);
table.AddColumn("Name");
table.AddColumn("Department");
table.AddColumn("Sales");
table.AddRow("Alice", "North", "$12,400");
table.AddRow("Bob", "South", "$8,750");
table.AddRow("Carol", "West", "$15,200");
AnsiConsole.Write(table);
Align Columns
To right-align a column, use .RightAligned() in the column configuration.
var table = new Table()
.RoundedBorder()
.BorderColor(Color.Grey);
table.AddColumn("Name");
table.AddColumn("Department", col => col.Centered());
table.AddColumn("Sales", col => col.RightAligned());
table.AddRow("Alice", "North", "$12,400");
table.AddRow("Bob", "South", "$8,750");
table.AddRow("Carol", "West", "$15,200");
AnsiConsole.Write(table);
Add a Title and Footer
If you need a title, use .Title(). For totals, set column footers.
var table = new Table()
.RoundedBorder()
.BorderColor(Color.Grey)
.Title("[yellow bold]Q4 Sales Report[/]");
table.AddColumn("Name");
table.AddColumn("Department", col => col.Centered());
table.AddColumn("Sales", col => col.RightAligned());
table.AddRow("Alice", "North", "$12,400");
table.AddRow("Bob", "South", "$8,750");
table.AddRow("Carol", "West", "$15,200");
// Add footer with totals
table.Columns[0].Footer = new Text("Total", new Style(decoration: Decoration.Bold));
table.Columns[1].Footer = new Text("");
table.Columns[2].Footer = new Text("$36,350", new Style(Color.Green, decoration: Decoration.Bold));
AnsiConsole.Write(table);
See Also
- Table Widget - Full table API reference
- Table Border Reference - All border styles