Fetch the repository succeeded.
/*
@Time : 2020/6/2 17:59
@Author : wayos
@File : xlsx.go
@Software: bill-service
*/
package excel
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
)
var (
axisIdx = [26]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",
}
)
// NewExcelBytes
func NewExcelBytes(data [][]interface{}) ([]byte, error) {
f := excelize.NewFile()
index := f.NewSheet(`Sheet1`)
for rowId, row := range data {
for colIdx, col := range row {
axis := fmt.Sprintf(`%s%d`, EscapeIdx(colIdx), rowId+1)
f.SetCellValue(`Sheet1`, axis, col)
}
}
f.SetActiveSheet(index)
if buff, err := f.WriteToBuffer(); err != nil {
return nil, err
} else {
return buff.Bytes(), nil
}
}
// EscapeIdx
func EscapeIdx(idx int) string {
var idxStr string
for true {
subIdx := idx % len(axisIdx)
idxStr = axisIdx[subIdx] + idxStr
idx -= subIdx
if idx <= len(axisIdx) {
break
}
}
return idxStr
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。