forked from extrame/xls
/
row.go
65 lines (53 loc) · 1.11 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
package xls
type rowInfo struct {
Index uint16
First uint16
Last uint16
Height uint16
Notused uint16
Notused2 uint16
Flags uint32
}
// Row the data of one row
type Row struct {
wb *WorkBook
info *rowInfo
cols map[uint16]contentHandler
}
// Column will return the index i cell of the row
func (r *Row) Column(i int) cell {
var serial = uint16(i)
if ch, ok := r.cols[serial]; ok {
return cell{ch}
}
for _, v := range r.cols {
if v.FirstCol() <= serial && v.LastCol() >= serial {
return cell{v}
}
}
return cell{nil}
}
// Col Get the Nth Column on the Row.
func (r *Row) Col(i int) string {
var val string
var serial = uint16(i)
if ch, ok := r.cols[serial]; ok {
val = ch.String(r.wb)[0]
} else {
for _, v := range r.cols {
if v.FirstCol() <= serial && v.LastCol() >= serial {
val = v.String(r.wb)[serial-v.FirstCol()]
break
}
}
}
return val
}
// FirstCol Get the number of First Col of the Row.
func (r *Row) FirstCol() int {
return int(r.info.First)
}
//LastCol Get the number of Last Col of the Row.
func (r *Row) LastCol() int {
return int(r.info.Last)
}