1 Star 4 Fork 2

tym_hmm/go-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ExoutHelper.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
天蝎儿 提交于 2022-06-06 14:19 . 增加数据导出到excel
package ExcelHelper
import (
"fmt"
"github.com/xuri/excelize/v2"
)
//excel个列的简称
//https://blog.csdn.net/wtt234/article/details/124531074
//
var CellCols = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
type writeExcel struct {
title []string
data [][]string
sheet string
}
func NewWriteExcel() *writeExcel {
return &writeExcel{}
}
func (this *writeExcel) SetTitle(title []string) {
this.title = title
}
func (this *writeExcel) SetData(data [][]string) {
this.data = data
}
func (this *writeExcel) SetShellNum(sheelNum int) {
this.sheet = fmt.Sprintf("Sheet%d", sheelNum)
}
func (this *writeExcel) Write(fileName string) error {
f := excelize.NewFile()
//titleLen := len(this.title)
var resltErr error
for k, v := range this.title {
resltErr = f.SetCellValue(this.sheet, fmt.Sprintf("%s%d", CellCols[k], 1), v)
if resltErr != nil {
break
}
}
if resltErr != nil {
return resltErr
}
//写入数据
LABEL_STOP:
for k, v := range this.data {
for kv, vv := range v {
resltErr = f.SetCellValue(this.sheet, fmt.Sprintf("%s%d", CellCols[kv], k+2), vv)
if resltErr != nil {
break LABEL_STOP
}
}
}
if resltErr != nil {
return resltErr
}
//保存
resltErr = f.SaveAs(fileName)
if resltErr != nil {
return resltErr
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tym_hmm/go-helper.git
git@gitee.com:tym_hmm/go-helper.git
tym_hmm
go-helper
go-helper
v1.1.153

搜索帮助