-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheet.go
More file actions
38 lines (32 loc) · 749 Bytes
/
sheet.go
File metadata and controls
38 lines (32 loc) · 749 Bytes
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
package table
import "github.com/tealeg/xlsx/v3"
// Sheet represents a sheet in a xlsx file.
type Sheet struct {
name string // name of the sheet.
rows []*Row // rows in the sheet.
}
// NewRow returns a new row from a sheet.
func (s *Sheet) NewRow() *Row {
row := &Row{cells: []*Cell{}}
s.rows = append(s.rows, row)
return row
}
// AddRows adds rows to the sheet.
func (s *Sheet) AddRows(rows ...*Row) {
s.rows = append(s.rows, rows...)
}
// render renders the sheet.
func (s *Sheet) render() (*xlsx.Sheet, error) {
sheet, err := xlsx.NewSheet(s.name)
if err != nil {
return nil, err
}
for _, row := range s.rows {
r := sheet.AddRow()
if row.height != 0 {
r.SetHeight(row.height)
}
row.render(r)
}
return sheet, nil
}