-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoxlsx.go
61 lines (52 loc) · 1.06 KB
/
toxlsx.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"strconv"
"github.com/tealeg/xlsx"
)
type SendCsvToXlsx struct {
file *xlsx.File
sheet *xlsx.Sheet
fname string
}
func NewSendCsvToXlsx() SendCsv {
xlsx.SetDefaultFont(11, "MS PGothic")
return &SendCsvToXlsx{
file: xlsx.NewFile(),
}
}
func (this *SendCsvToXlsx) NewSheet(name string) error {
sheet, err := this.file.AddSheet(name)
if err != nil {
return err
}
this.sheet = sheet
return nil
}
func (this *SendCsvToXlsx) Send(csv1 []string) error {
row := this.sheet.AddRow()
for _, val := range csv1 {
cell := row.AddCell()
style := cell.GetStyle()
style.Alignment.WrapText = true
style.Alignment.Vertical = "center"
cell.SetStyle(style)
if rxNumber.MatchString(val) {
if f, err := strconv.ParseFloat(val, 64); err == nil {
cell.SetFloat(f)
continue
}
}
cell.SetString(val)
}
return nil
}
func (this *SendCsvToXlsx) Close() {
if this.fname != "" {
this.file.Save(this.fname)
}
}
func (this *SendCsvToXlsx) SetDoQuit(bool) {
}
func (this *SendCsvToXlsx) SetSaveAs(name string) {
this.fname = name
}