-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.go
42 lines (37 loc) · 1.07 KB
/
export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package excel
import (
"log"
"github.com/xuri/excelize/v2"
)
func NewFile(sheet string, header []string) *excelize.File {
endColumn := ColumnLetter[len(header)-1]
f := excelize.NewFile()
//单元格样式
style, err := f.NewStyle(Style)
f.SetColStyle(sheet, "A:"+endColumn, style)
headerStyle, _ := f.NewStyle(HeaderStyle)
f.SetCellStyle(sheet, "A1", endColumn+"1", headerStyle)
if err != nil {
log.Println(err)
}
for i := range header {
/* axis, _ := excelize.CoordinatesToCellName(i+1, 1)
f.SetCellValue(sheet, axis, header[i])*/
f.SetCellValue(sheet, ColumnLetter[i]+"1", header[i])
}
f.SetRowHeight(sheet, 1, 30)
return f
}
func NewSheet(f *excelize.File, sheet string, header []string) {
endColumn := ColumnLetter[len(header)-1]
//单元格样式
style, _ := f.NewStyle(Style)
headerStyle, _ := f.NewStyle(HeaderStyle)
f.NewSheet(sheet)
f.SetColStyle(sheet, "A:"+endColumn, style)
f.SetCellStyle(sheet, "A1", endColumn+"1", headerStyle)
for i := range header {
f.SetCellValue(sheet, ColumnLetter[i]+"1", header[i])
}
f.SetRowHeight(sheet, 1, 30)
}