代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。