diff options
author | George Abbott <george@gabbott.dev> | 2023-11-01 22:31:09 +0000 |
---|---|---|
committer | George Abbott <george@gabbott.dev> | 2023-11-01 22:31:09 +0000 |
commit | d7ba131e756057307499fb2c3349c43e8e2fd38c (patch) | |
tree | 4d040e821f32f0c5fb3a4a7eadf57a4eeae5667c /values.go |
Diffstat (limited to 'values.go')
-rw-r--r-- | values.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/values.go b/values.go new file mode 100644 index 0000000..a04a25a --- /dev/null +++ b/values.go @@ -0,0 +1,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 +} |