-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrow.go
More file actions
96 lines (85 loc) · 1.83 KB
/
row.go
File metadata and controls
96 lines (85 loc) · 1.83 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package xlsxtra
import "github.com/tealeg/xlsx"
// Row of a sheet
type Row struct {
*xlsx.Row
}
// AddBool adds a cell with bool as 1 or 0 to a row
func (row *Row) AddBool(x ...bool) *xlsx.Cell {
var cell *xlsx.Cell
for _, y := range x {
if y {
cell = row.AddInt(1)
} else {
cell = row.AddInt(0)
}
}
return cell
}
// AddEmpty adds n empty cells to a row
func (row *Row) AddEmpty(n int) {
for i := 0; i < n; i++ {
row.AddCell()
}
}
// AddFloat adds a cell with float64 value to a row
func (row *Row) AddFloat(format string, x ...float64,
) *xlsx.Cell {
var cell *xlsx.Cell
for _, y := range x {
cell = row.AddCell()
cell.SetFloatWithFormat(y, format)
}
return cell
}
// AddFormula adds a cell with formula to a row
func (row *Row) AddFormula(format string,
formula ...string) *xlsx.Cell {
var cell *xlsx.Cell
for _, y := range formula {
cell = row.AddCell()
cell.SetFormula(y)
cell.NumFmt = format
}
return cell
}
// AddInt adds a cell with int value to a row
func (row *Row) AddInt(x ...int) *xlsx.Cell {
var cell *xlsx.Cell
for _, y := range x {
cell = row.AddCell()
cell.SetInt(y)
}
return cell
}
// AddString adds a cell with string value to a row
func (row *Row) AddString(x ...string) *xlsx.Cell {
var cell *xlsx.Cell
for _, y := range x {
cell = row.AddCell()
cell.SetString(y)
}
return cell
}
// SetStyle set style to all cells of a row
func (row *Row) SetStyle(style *xlsx.Style) {
for _, cell := range row.Cells {
cell.SetStyle(style)
}
}
// ToString converts row to string slice
func ToString(cells []*xlsx.Cell) []string {
s := make([]string, len(cells))
for i, cell := range cells {
s[i] = cell.Value
}
return s
}
// Rows converts slice of xlsx.Row into Row
func Rows(rows []*xlsx.Row) []*Row {
r := make([]*Row, len(rows))
for i, row := range rows {
r[i] = &Row{row}
}
return r
}