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
|
package saggytrousers
import (
xl "anyxcelize"
"fmt"
)
// Provides functions for getting the header as []string and the body (except
// the header) as [][]any, which can be passed into other functions from there.
func GetHeader(file *xl.File, sheet string) []string {
rows, err := file.Rows(sheet)
if err != nil {
str := fmt.Sprintf("st.GetHeader: call to Rows(sheet: %s) failed with error %v", sheet, err)
panic(str)
}
rows.Next()
header, err := rows.Columns()
if err != nil {
str := fmt.Sprintf("st.GetHeader: Could not get a header.")
panic(str)
}
return header
}
// Get all rows, except the header.
func GetRows(file *xl.File, sheet string) [][]any {
rows, err := file.GetRowsGeneric(sheet)
if err != nil {
str := fmt.Sprintf("saggytrousers.GetRows: call to GetRowsGeneric(%s) failed with error %v", sheet, err)
panic(str)
}
return rows[1:]
}
func GetColumns(file *xl.File, sheet string) [][]any {
cols, err := file.GetColsGeneric(sheet)
if err != nil {
str := fmt.Sprintf("saggytrousers.GetColumns: call to GetRowsGeneric(%s) failed with error %v", sheet, err)
panic(str)
}
var ret [][]any
for _, sa := range cols {
exceptFirst := sa[1:]
ret = append(ret, exceptFirst)
}
return ret
}
|