forked from kardianos/xls
/
row.go
71 lines (64 loc) · 1.43 KB
/
row.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
62
63
64
65
66
67
68
69
70
71
package xls
type rowInfo struct {
Index uint16
Fcell uint16
Lcell uint16
Height uint16
Notused uint16
Notused2 uint16
Flags uint32
}
// Row handle.
type Row struct {
wb *WorkBook
info *rowInfo
Cols map[uint16]contentHandler
}
// Col gets the n'th column (zero-based). If not found it will return empty string.
// Merged cells will be reported more then once if iterating.
func (r *Row) Col(n int) string {
serial := uint16(n)
if ch, ok := r.Cols[serial]; ok {
strs := ch.String(r.wb)
return strs[0]
}
for _, v := range r.Cols {
if v.FirstCol() <= serial && v.LastCol() >= serial {
strs := v.String(r.wb)
return strs[serial-v.FirstCol()]
}
}
return ""
}
// ColExact gets the n'th column (zero-based). If not found it will return empty string.
// Merged cells will only show the value at the first cell.
func (r *Row) ColExact(n int) string {
serial := uint16(n)
if ch, ok := r.Cols[serial]; ok {
strs := ch.String(r.wb)
for _, s := range strs {
if len(s) == 0 {
continue
}
return s
}
return ""
}
return ""
}
// Value of the cell.
func (r *Row) Value(n int) CellValue {
serial := uint16(n)
if ch, ok := r.Cols[serial]; ok {
return ch.Value(r.wb)
}
return CellValue{}
}
// LastCol gets the index of the last column.
func (r *Row) LastCol() int {
return int(r.info.Lcell)
}
// FirstCol gets the index of the first column.
func (r *Row) FirstCol() int {
return int(r.info.Fcell)
}