在为自己编写一个小型C#应用程序时,我意识到,如果我可以轻松地以textmode绘制表格,那将会很整洁。你知道,像这样:
+-----------------+-----------------+
| 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 |
+--------+--------+--------+--------+
谷歌快速搜索没有发现任何问题。有没有类似现成的东西,还是我应该自己推出?
已添加:理想版本将支持:
但是我也愿意减少。 :)
最佳答案
这是您要寻找的那个
http://www.phpguru.org/static/ConsoleTable.html
要么
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 | | |
+--------------+---------------+--------------+