diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2019-12-03 17:17:10 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2019-12-03 17:17:10 +0000 |
commit | 8ac4a42c58f6dfb65ddfaef38d137ab1b2280e41 (patch) | |
tree | 40893511af035d3fd5b1b6d6507d49ae8b9ef077 | |
parent | 182e71afccb8ef649e9738aa8034c9c2cdfcfd7a (diff) |
removed all coords code
-rw-r--r-- | reader/reader.go | 34 | ||||
-rw-r--r-- | reader/reader_test.go | 48 |
2 files changed, 2 insertions, 80 deletions
diff --git a/reader/reader.go b/reader/reader.go index 5ba40ae..22dd003 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -10,14 +10,10 @@ import ( "path/filepath" "strings" + "github.com/hammerheadlemon/coords" "github.com/tealeg/xlsx" ) -const ( - maxCols = 16384 - maxAlphabets = (maxCols / 26) - 1 -) - type ( // Data from the sheet. SheetData map[string]ExtractedCell @@ -27,8 +23,6 @@ type ( ExtractedData map[string]map[string]xlsx.Cell ) -var colstream = cols(maxAlphabets) - //DatamapLine - a line from the datamap. type DatamapLine struct { Key string @@ -96,30 +90,6 @@ func ReadDML(path string) ([]DatamapLine, error) { return s, nil } -//alphabet generates all the letters of the alphabet. -func alphabet() []string { - letters := make([]string, 26) - for idx := range letters { - letters[idx] = string('A' + byte(idx)) - } - return letters -} - -//cols generates the alpha column compont of Excel cell references -//Adds n alphabets to the first (A..Z) alphabet. -func cols(n int) []string { - out := alphabet() - alen := len(out) - tmp := make([]string, alen) - copy(tmp, out) - for cycle := 0; cycle < n; cycle++ { - for y := 0; y < alen; y++ { - out = append(out, out[(cycle+2)-2]+tmp[y]) - } - } - return out -} - //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. @@ -139,7 +109,7 @@ func ReadXLSX(ssheet string) FileData { for colLidx, cell := range row.Cells { ex := ExtractedCell{ Cell: cell, - Col: colstream[colLidx], + Col: coords.Colstream[colLidx], Row: rowLidx + 1, Value: cell.Value} cellref := fmt.Sprintf("%s%d", ex.Col, ex.Row) diff --git a/reader/reader_test.go b/reader/reader_test.go index 4be02df..d6d29fb 100644 --- a/reader/reader_test.go +++ b/reader/reader_test.go @@ -38,54 +38,6 @@ func TestBadDMLLine(t *testing.T) { } } -func TestAlphaStream(t *testing.T) { - if colstream[26] != "AA" { - t.Errorf("The test expected AA, got %v.", colstream[26]) - } - if len(colstream) > maxCols { - t.Errorf(`Number of columns in alphastream exceeds Excel maximum. - alphastream contains %d, maxCols is %d`, len(colstream), maxCols) - } -} - -func TestAlphaSingle(t *testing.T) { - ab := alphabet() - if ab[0] != "A" { - t.Errorf("The test expected A, got %v.", ab[0]) - } - if ab[1] != "B" { - t.Errorf("The test expected B, got %v.", ab[1]) - } - if ab[25] != "Z" { - t.Errorf("The test expected Z, got %v.", ab[25]) - } -} - -func TestAlphas(t *testing.T) { - a := 2 // two alphabets long - ecs := cols(a) - cases := []struct { - col int - val string - }{ - {0, "A"}, - {25, "Z"}, - {26, "AA"}, - {52, "BA"}, - } - for _, c := range cases { - // we're making sure we can pass that index - r := 26 * a - if c.col > r { - t.Fatalf("Cannot use %d as index to array of %d", c.col, r) - } - if got := ecs[c.col]; got != c.val { - t.Errorf("The test expected ecs[%d] to be %s - got %s.", - c.col, c.val, ecs[c.col]) - } - } -} - func TestGetSheetsFromDM(t *testing.T) { slice, _ := ReadDML("testdata/datamap.csv") sheetNames := getSheetNames(slice) |