-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtable_getter.go
49 lines (45 loc) · 917 Bytes
/
table_getter.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
package herschel
import "strconv"
// GetStringValue returns value of cell as string.
func (t *Table) GetStringValue(row int, col int) string {
v := t.GetValue(row, col)
if v != nil {
if s, ok := v.(string); ok {
return s
}
}
return ""
}
// GetIntValue returns value of cell as int.
func (t *Table) GetIntValue(row int, col int) int {
v := t.GetValue(row, col)
if v != nil {
if i, ok := v.(int); ok {
return i
}
if s, ok := v.(string); ok {
if i, err := strconv.Atoi(s); err == nil {
return i
}
}
}
return 0
}
// GetInt64Value returns value of cell as int.
func (t *Table) GetInt64Value(row int, col int) int64 {
v := t.GetValue(row, col)
if v != nil {
if i, ok := v.(int64); ok {
return i
}
if i, ok := v.(int); ok {
return int64(i)
}
if s, ok := v.(string); ok {
if i, err := strconv.ParseInt(s, 10, 64); err == nil {
return i
}
}
}
return 0
}