1 Star 0 Fork 0

清汤兔子面 / tobox

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
xlsx.go 994 Bytes
Copy Edit Raw Blame History
agent_iyyn authored 2020-09-25 22:14 . first commit modules.
/*
@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
}
Go
1
https://gitee.com/agent_iyyn/tobox.git
git@gitee.com:agent_iyyn/tobox.git
agent_iyyn
tobox
tobox
v0.1.2

Search