diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-15 14:32:11 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-15 14:32:11 +0000 |
commit | 3cf5ecab1c0f1d3b35841bd41ac2a838ecaab6be (patch) | |
tree | 3403348ece0723befcda9c752a7c701b85c82f21 /reader | |
parent | 9835833c0d1fc3c59c0619cc4cda5359ddba3a4c (diff) |
removed dependency on datamap file
Diffstat (limited to 'reader')
-rw-r--r-- | reader/reader.go | 21 | ||||
-rw-r--r-- | reader/reader_test.go | 11 |
2 files changed, 12 insertions, 20 deletions
diff --git a/reader/reader.go b/reader/reader.go index 55966af..9aca448 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -122,25 +122,14 @@ func cols(n int) []string { //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 { - - // TODO - to implement filtering by Datamap, - // pull the data first, then go through each - // item in the dmlData slice to check for sheet/cellref - // matches, and then return them. Duplicate this func - // to do so +func ReadXLSX(ssheet string) FileData { // open the files excelData, err := xlsx.OpenFile(ssheet) if err != nil { log.Fatal(err) } - dmlData, err := ReadDML(dm) - if err != nil { - log.Fatal(err) - } - sheetNames := getSheetNames(dmlData) - output := make(FileData, len(sheetNames)) + output := make(FileData, 1) // get the data for _, sheet := range excelData.Sheets { @@ -162,17 +151,17 @@ func ReadXLSX(dm string, ssheet string) FileData { } //Extract returns the file's data as a map, -// keyed on sheet name. All values are returned as strings. +// using the datamap as a filter, 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) + data := ReadXLSX(ssheet) dmlData, err := ReadDML(dm) if err != nil { log.Fatal(err) } sheetNames := getSheetNames(dmlData) output := make(ExtractedData, len(sheetNames)) - inner := make(map[string]xlsx.Cell) for _, i := range dmlData { diff --git a/reader/reader_test.go b/reader/reader_test.go index eab6848..d39f6df 100644 --- a/reader/reader_test.go +++ b/reader/reader_test.go @@ -87,7 +87,7 @@ func TestGetSheetsFromDM(t *testing.T) { } func TestReadXLSX(t *testing.T) { - d := ReadXLSX("testdata/datamap.csv", "testdata/test_template.xlsx") + d := ReadXLSX("testdata/test_template.xlsx") if d["Summary"]["A2"].Value != "Date:" { t.Errorf("Expected A2 in Summary sheet to be 'Date:' - instead it is %s", d["Summary"]["A2"].Value) } @@ -102,12 +102,15 @@ func TestReadXLSX(t *testing.T) { func TestExtract(t *testing.T) { d := Extract("testdata/datamap.csv", "testdata/test_template.xlsx") if d["Introduction"]["C9"].Value != "Test Department" { - t.Errorf("Expected C9 in Introduction sheet to be Test Department - instead it is %s", d["Introduction"]["C9"].Value) + t.Errorf("Expected C9 in Introduction sheet to be Test Department "+ + "- instead it is %s", d["Introduction"]["C9"].Value) } if d["Introduction"]["J9"].Value != "Greedy Parrots" { - t.Errorf("Expected J9 in Introduction sheet to be Greedy Parrots - instead it is %s", d["Introduction"]["J9"].Value) + t.Errorf("Expected J9 in Introduction sheet to be Greedy Parrots "+ + "- instead it is %s", d["Introduction"]["J9"].Value) } if d["Introduction"]["A1"].Value != "10" { - t.Errorf("Expected A1 in Introduction sheet to be 10 - instead it is %s", d["Introduction"]["A1"].Value) + t.Errorf("Expected A1 in Introduction sheet to be 10 - instead "+ + "it is %s", d["Introduction"]["A1"].Value) } } |