-
Notifications
You must be signed in to change notification settings - Fork 0
/
createExcelFile.go
45 lines (37 loc) · 936 Bytes
/
createExcelFile.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
43
44
45
package main
import (
"fmt"
"strconv"
"github.com/xuri/excelize/v2"
)
func toExcel(table [][]string, filename string) string {
f, err := excelize.OpenFile(filename)
if err != nil {
fmt.Println(err)
return "Problem at opening file!"
}
col := []string{"A", "B", "C", "D", "E", "F"}
f.NewSheet("TermExtList")
for num0, slice := range table {
//fmt.Println(len(slice))
//fmt.Printf("num0: %d \n", num0)
for num1, el := range slice {
//fmt.Println("Wert: " + el)
//fmt.Printf("num1: %d \n", num1)
cell := col[num1] + strconv.Itoa(num0+1)
//fmt.Println(cell)
f.SetCellValue("TermExtList", cell, el)
}
}
style, err := f.NewStyle(`{"font":{"bold": true}}`)
if err != nil {
fmt.Println(err)
}
f.SetColWidth("TermExtList", "A", "D", 30.0)
f.SetCellStyle("TermExtList", "A1", "D1", style)
if err := f.Save(); err != nil {
fmt.Println(err)
return "Problem at saving!"
}
return "Success"
}