是否有任何.NET库在控制台(textmode)中绘制表格?

Vil*_*lx- 2 .net console

在为自己编写一个小型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 |
+--------+--------+--------+--------+
Run Code Online (Sandbox Code Playgroud)

快速的谷歌搜索没有透露任何信息.有没有这样的现成品,或者我应该推出自己的?

补充:理想版本支持:

  • 行/列跨度;
  • 不同的边框宽度和样式;
  • 水平和垂直文本对齐方式

但我也会满足于少.:)

Tzu*_*hay 9

这是您正在寻找的 http://www.phpguru.org/static/ConsoleTable.htmlhttp://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        |               |              |
+--------------+---------------+--------------+
Run Code Online (Sandbox Code Playgroud)