Are there .NET libraries that draw a table in the console (text mode)?
While writing a small C # application for myself, I realized that it would be neat if I could draw tables easily in text mode. You know, like this:
+-----------------+-----------------+
| Header 1 | Header 2 |
+--------+--------+--------+--------+
| Data 1 | Data 2 | Data 3 | Data 4 |
| Data 1 | Data 2 | Data 3 | Data 4 |
| Data 1 | Data 2 | Data 3 | Data 4 |
+--------+--------+--------+--------+
A quick google search showed nothing. Is there something like this out of the box, or should I deploy my own?
Added: Ideal version will support:
- Spreads of rows / columns;
- Various widths and styles of borders;
- Horizontal and vertical text alignment
But I'll settle for less. :)
+2
source to share
1 answer
This is the one you are looking for http://www.phpguru.org/static/ConsoleTable.html or http://www.phpguru.org/downloads/csharp/ConsoleTable/ConsoleTable.cs
ConsoleTable table = new ConsoleTable();
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.SetHeaders(new string[] {"First Column", "Second Column", "Third Column"});
table.SetFooters(new string[] {"Yabba"});
table.InsertRow(new string[] {"", "ferfr", "frf r"}, 7);
table.PrependRow(new string[] {});
System.Console.Write(table.ToString());
Produces...
+--------------+---------------+--------------+
| First Column | Second Column | Third Column |
+--------------+---------------+--------------+
| | | |
| foo | bar | jello |
| foo | bar | jello |
| foo | bar | jello |
| foo | bar | jello |
| | | |
| | | |
| | | |
| | ferfr | frf r |
+--------------+---------------+--------------+
| Yabba | | |
+--------------+---------------+--------------+
+9
source to share