本文主要是介绍Golang:使用bndr/gotabulate实现美观的打印表格数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
bndr/gotabulate 可以使用 Go 语言简单、美观的打印表格数据
文档
- https://pkg.go.dev/github.com/bndr/gotabulate
- https://github.com/bndr/gotabulate
安装
go get github.com/bndr/gotabulate
代码示例
package mainimport ("fmt""github.com/bndr/gotabulate"
)func main() {// Create Some Fake Rowsrow_1 := []interface{}{"john", 20, "ready"}row_2 := []interface{}{"bndr", 23, "ready"}// Create an object from 2D interface arrayt := gotabulate.Create([][]interface{}{row_1, row_2})// Set the Headers (optional)t.SetHeaders([]string{"name", "age", "status"})// Set the Empty String (optional)t.SetEmptyString("None")// Set Align (Optional)t.SetAlign("center")// Print the result: grid, or simplefmt.Println(t.Render("grid"))
}
输出
+---------+--------+-----------+
| name | age | status |
+=========+========+===========+
| john | 20 | ready |
+---------+--------+-----------+
| bndr | 23 | ready |
+---------+--------+-----------+
这篇关于Golang:使用bndr/gotabulate实现美观的打印表格数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!