是否有任何用于绘制 ASCII 表的 Java 库?

2022-09-02 10:38:41

我需要将数据作为表输出到控制台中。我想知道也许有一些java库可以处理ASCII艺术中的绘图表,对齐单元格内的值等?

 ╔══════╤═══════════╤════════╗
 ║  ID  │ Name      │  Age   ║ 
 ╠══════╪═══════════╪════════╣
 ║  1   │ John      │   24   ║ 
 ╟──────┼───────────┼────────╢
 ║  2   │ Jeff      │   19   ║ 
 ╟──────┼───────────┼────────╢
 ║  3   │ Joel      │   42   ║ 
 ╚══════╧═══════════╧════════╝

答案 1

这对我来说效果很好:http://code.google.com/p/java-ascii-table/

String [] header = {
      "User Name", 
      "Salary", "Designation",
      "Address", "Lucky#"
};

String[][] data = {
      { "Ram", "2000", "Manager", "#99, Silk board", "1111"  },
      { "Sri", "12000", "Developer", "BTM Layout", "22222" },
      { "Prasad", "42000", "Lead", "#66, Viaya Bank Layout", "333333" },
      { "Anu", "132000", "QA", "#22, Vizag", "4444444" },
      { "Sai", "62000", "Developer", "#3-3, Kakinada"  },
      { "Venkat", "2000", "Manager"   },
      { "Raj", "62000"},
      { "BTC"},
};

这将呈现以下内容:

+-----------+--------+-------------+------------------------+---------+
| User Name | Salary | Designation |         Address        |  Lucky# |
+-----------+--------+-------------+------------------------+---------+
|       Ram |   2000 |     Manager |        #99, Silk board |    1111 |
|       Sri |  12000 |   Developer |             BTM Layout |   22222 |
|    Prasad |  42000 |        Lead | #66, Viaya Bank Layout |  333333 |
|       Anu | 132000 |          QA |             #22, Vizag | 4444444 |
|       Sai |  62000 |   Developer |         #3-3, Kakinada |         |
|    Venkat |   2000 |     Manager |                        |         |
|       Raj |  62000 |             |                        |         |
|       BTC |        |             |                        |         |
+-----------+--------+-------------+------------------------+---------+

推荐