aboutsummaryrefslogtreecommitdiffstats
path: root/reader/reader.go
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-11-12 15:24:33 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2019-11-12 15:24:33 +0000
commitf2fe102b3674d43144ec47e4df7246daef4626df (patch)
treebf16c95ecec6328b7ee3a458a13d4dba297f7118 /reader/reader.go
parent4eb808382d1d8c53f5d0bffc18b16bf911fe96d2 (diff)
pretty much can filter by datamap by needs more tests
Diffstat (limited to 'reader/reader.go')
-rw-r--r--reader/reader.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/reader/reader.go b/reader/reader.go
index e0c3f66..71870c5 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -22,6 +22,8 @@ type (
SheetData map[string]ExtractedCell
// Data from the file.
FileData map[string]SheetData
+ // Data from the file, filtered by a Datamap.
+ ExtractedData map[string]map[string]xlsx.Cell
)
var colstream = cols(maxAlphabets)
@@ -117,7 +119,7 @@ func cols(n int) []string {
return out
}
-//ReadXLSToMap returns the file's data as a map,
+//ReadXLSX returns the file's data as a map,
// keyed on sheet name. All values are returned as strings.
// Paths to a datamap and the spreadsheet file required.
func ReadXLSX(dm string, ssheet string) FileData {
@@ -158,3 +160,30 @@ func ReadXLSX(dm string, ssheet string) FileData {
}
return output
}
+
+//Extract returns the file's data as a map,
+// keyed on sheet name. All values are returned as strings.
+// Paths to a datamap and the spreadsheet file required.
+func Extract(dm string, ssheet string) ExtractedData {
+ data := ReadXLSX(dm, ssheet)
+ dmlData, err := ReadDML(dm)
+ if err != nil {
+ log.Fatal(err)
+ }
+ sheetNames := getSheetNames(dmlData)
+ output := make(ExtractedData, len(sheetNames))
+
+ for _, i := range dmlData {
+ sheet := i.Sheet
+ cellref := i.Cellref
+ if val, ok := data[sheet][cellref]; ok {
+ // TODO check what is happening here...
+ // ddg "golang assingment to entry in nil map"
+ // first SO entry, but I don't think I totally understand
+ inner := make(map[string]xlsx.Cell)
+ inner[cellref] = *val.Cell
+ output[sheet] = inner
+ }
+ }
+ return output
+}