From f2fe102b3674d43144ec47e4df7246daef4626df Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 12 Nov 2019 15:24:33 +0000 Subject: pretty much can filter by datamap by needs more tests --- reader/reader.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'reader/reader.go') 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 +} -- cgit v1.2.3