diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-03 21:33:41 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-03 21:33:41 +0000 |
commit | 29ba5464c10d681b39f8e65b07f533d8f43f1b45 (patch) | |
tree | fab298330fbe68eba0b005414cdd7b65853d9ef1 | |
parent | b86942c3eaf0ad7670b03b432f17c721c836adef (diff) |
implemented alphas - producing letter component of Excel columns horizontally
Diffstat (limited to '')
-rw-r--r-- | reader/reader.go | 36 | ||||
-rw-r--r-- | reader/reader_test.go | 18 |
2 files changed, 38 insertions, 16 deletions
diff --git a/reader/reader.go b/reader/reader.go index 465f242..d8ab23c 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -75,28 +75,34 @@ var lowerAlpha [2]string = [2]string{"A", "B"} // two alphabet lengths const ablen int = 52 -func alphas() []string { - acount := 0 - lets := make([]string, ablen) - for i, _ := range lets { - if i == 0 { - lets[i] = "A" - continue - } - if i%26 != 0 { - lets[i] = string('A' + byte(i)) - } else { - acount++ - lets[i] = string(64+acount) + string('A'+byte(i)) +//alphSingle generates all the letters of the alphabet +func alphaSingle() []string { + letters := make([]string, 26) + for idx := range letters { + letters[idx] = string('A' + byte(idx)) + } + return letters +} + +//alphas generates the alpha column compont of Excel cell references +//Combines n alphabets to do this. +func alphas(n int) []string { + single := alphaSingle() + slen := len(single) + tmp := make([]string, len(single)) + copy(tmp, single) + for cycle := 0; cycle < n; cycle++ { + for y := 0; y < slen; y++ { + single = append(single, single[(cycle+2)-2]+tmp[y]) } } - return lets + return single } //ReadXLSX reads an XLSX file func ReadXLSX(excelFileName string) []ExtractedCell { var out []ExtractedCell - alphs := alphas() + alphs := alphas(2) for _, l := range alphs { fmt.Printf("Letter: %s", string(l)) } diff --git a/reader/reader_test.go b/reader/reader_test.go index 563f2fc..fe58445 100644 --- a/reader/reader_test.go +++ b/reader/reader_test.go @@ -42,8 +42,21 @@ func TestReadXLSX(t *testing.T) { _ = ReadXLSX("testdata/test_template.xlsx") // TODO: remove temp blank } +func TestAlphaSingle(t *testing.T) { + as := alphaSingle() + if as[0] != "A" { + t.Errorf("Expected A, got %v", as[0]) + } + if as[1] != "B" { + t.Errorf("Expected B, got %v", as[1]) + } + if as[25] != "Z" { + t.Errorf("Expected Z, got %v", as[25]) + } +} + func TestAlphas(t *testing.T) { - as := alphas() + as := alphas(2) if as[0] != "A" { t.Errorf("Expected A, got %v", as[0]) } @@ -53,5 +66,8 @@ func TestAlphas(t *testing.T) { if as[26] != "AA" { t.Errorf("Expected AA, got %v", as[26]) } + if as[52] != "BA" { + t.Errorf("Expected BA, got %v", as[52]) + } } |