go-image-table
介绍
golang生成图片表格
获取组件包
go get -u -insecure gitee.com/yebetter/go-image-table
安装教程
//初始化句柄
tb := TableImage.NewTableImageClient()
//表格配置参数
conf := &TableImage.TableImageConf{
Margin: 20, //距离四周的边界值
MarginTop: 55, //距离顶部的边界值
Padding: 10, //每个单元格的内边距
FontPointTitle: 22, //标题字体占用的像素点
FontPointDate: 16, //日期字体占用的像素点
OutLineWidth: 2, //外边框线条宽度
InLineWidth: 1, //内边框线条宽度
FontPath: "../ttf/FangZhengKaiTi.ttf", //字体路径
Rows: 6, //多少行
RowHight: 50, //行高
Columns: 10, //多少列
ColumnWidth: 110, //列宽
}
//初始化
tb.InitTableImage(conf)
//标题,备注
title := "数据核对表"
mark := "时间:" + Time.GetNowTimeStr()
//表头
dataTitle := []TableImage.TitleParse{
TableImage.TitleParse{
Field: "Name",
Name: "名字",
},
TableImage.TitleParse{
Field: "Sex",
Name: "性别",
},
TableImage.TitleParse{
Field: "Score",
Name: "分数",
},
TableImage.TitleParse{
Field: "Xuexiao",
Name: "学校",
},
TableImage.TitleParse{
Field: "Addr",
Name: "地址",
},
TableImage.TitleParse{
Field: "Level",
Name: "等级",
},
TableImage.TitleParse{
Field: "Mark",
Name: "备注1",
},
TableImage.TitleParse{
Field: "Mark2",
Name: "备注2",
},
TableImage.TitleParse{
Field: "Mark3",
Name: "备注3",
},
TableImage.TitleParse{
Field: "Mark4",
Name: "备注4",
},
}
//表格数据
data := []map[string]interface{}{}
for i := 1; i <= 5; i++ {
str := strconv.Itoa(i)
score := rand.Float64()
item := map[string]interface{}{
"Name": "名字" + str,
"Sex": "性别" + str,
"Score": score,
"Xuexiao": "某学" + str,
"Addr": "无路" + str,
"Level": i + 1,
"Mark": "加" + str,
"Mark2": "符2" + str,
"Mark3": "加3" + str,
"Mark4": "让4" + str,
}
data = append(data, item)
}
//保存路径
path := "../images/test4.png"
//创建表格
tb.CreateImage().SetTitle(title, mark).CreateTable(dataTitle, data).SaveImage(path)
效果展示