-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrow.go
More file actions
58 lines (49 loc) · 1.09 KB
/
row.go
File metadata and controls
58 lines (49 loc) · 1.09 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
package table
import (
"github.com/tealeg/xlsx/v3"
)
// Row represents a row in a sheet.
type Row struct {
cells []*Cell // cells in the row.
height float64 // height of the row.
}
// SetHeight sets the height of the row.
func (r *Row) SetHeight(h float64) *Row {
r.height = h
return r
}
// NewRow returns a new row.
func NewRow() *Row {
return &Row{cells: []*Cell{}}
}
// NewCell returns a new cell from a row.
func (r *Row) NewCell() *Cell {
cell := &Cell{}
r.cells = append(r.cells, cell)
return cell
}
// AddCells adds cells to a row.
func (r *Row) AddCells(cells ...*Cell) *Row {
r.cells = append(r.cells, cells...)
return r
}
// IterCells iterates over the cells in the row and calls the function f.
func (r *Row) IterCells(f func(int, *Cell) error) {
for i, c := range r.cells {
f(i, c)
}
}
// MergeRows merges multiple rows.
func MergeRows(rows ...*Row) *Row {
row := NewRow()
for _, r := range rows {
row.AddCells(r.cells...)
}
return row
}
// render renders the row.
func (r *Row) render(row *xlsx.Row) {
for _, cell := range r.cells {
cell.render(row.AddCell())
}
}