aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--reader/reader.go36
-rw-r--r--reader/reader_test.go42
2 files changed, 39 insertions, 39 deletions
diff --git a/reader/reader.go b/reader/reader.go
index 81b692d..bd0a1f0 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -17,7 +17,7 @@ const (
maxAlphabets = (maxCols / 26) - 1
)
-var alphaStream = alphas(maxAlphabets)
+var colstream = cols(maxAlphabets)
//DatamapLine - a line from the datamap.
type DatamapLine struct {
@@ -68,8 +68,8 @@ func ReadDML(path string) ([]DatamapLine, error) {
return s, nil
}
-//alphSingle generates all the letters of the alphabet
-func alphaSingle() []string {
+//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))
@@ -77,40 +77,40 @@ func alphaSingle() []string {
return letters
}
-//alphas generates the alpha column compont of Excel cell references
+//cols generates the alpha column compont of Excel cell references
//Adds n alphabets to the first (A..Z) alphabet.
-func alphas(n int) []string {
- single := alphaSingle()
- slen := len(single)
- tmp := make([]string, len(single))
- copy(tmp, single)
+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 < slen; y++ {
- single = append(single, single[(cycle+2)-2]+tmp[y])
+ for y := 0; y < alen; y++ {
+ out = append(out, out[(cycle+2)-2]+tmp[y])
}
}
- return single
+ return out
}
//ReadXLSX reads an XLSX file
-func ReadXLSX(excelFileName string) []ExtractedCell {
+func ReadXLSX(fn string) []ExtractedCell {
var out []ExtractedCell
- xlFile, err := xlsx.OpenFile(excelFileName)
+ f, err := xlsx.OpenFile(fn)
if err != nil {
- fmt.Printf("Cannot open %s", excelFileName)
+ fmt.Printf("Cannot open %s", fn)
}
- for _, sheet := range xlFile.Sheets {
+ for _, sheet := range f.Sheets {
for rowLidx, row := range sheet.Rows {
for colLidx, cell := range row.Cells {
ex := ExtractedCell{
cell: cell,
- colL: alphaStream[colLidx],
+ colL: colstream[colLidx],
rowLidx: rowLidx + 1,
value: cell.Value}
out = append(out, ex)
text := cell.String()
log.Printf("Sheet: %s Row: %d Col: %q Value: %s\n",
- sheet.Name, ex.rowLidx, alphaStream[colLidx], text)
+ sheet.Name, ex.rowLidx, colstream[colLidx], text)
}
}
}
diff --git a/reader/reader_test.go b/reader/reader_test.go
index 5f2b5f5..ca1c7c6 100644
--- a/reader/reader_test.go
+++ b/reader/reader_test.go
@@ -53,42 +53,42 @@ func TestReadXLSX(t *testing.T) {
}
func TestAlphaStream(t *testing.T) {
- if alphaStream[26] != "AA" {
- t.Errorf("Expected AA, got %v", alphaStream[26])
+ if colstream[26] != "AA" {
+ t.Errorf("Expected AA, got %v", colstream[26])
}
- if len(alphaStream) > maxCols {
+ if len(colstream) > maxCols {
t.Errorf(`Number of columns in alphastream exceeds Excel maximum.
- alphastream contains %d, maxCols is %d`, len(alphaStream), maxCols)
+ alphastream contains %d, maxCols is %d`, len(colstream), maxCols)
}
- log.Printf("Length of alphastream: %d", len(alphaStream))
+ log.Printf("Length of alphastream: %d", len(colstream))
}
func TestAlphaSingle(t *testing.T) {
- as := alphaSingle()
- if as[0] != "A" {
- t.Errorf("Expected A, got %v", as[0])
+ ab := alphabet()
+ if ab[0] != "A" {
+ t.Errorf("Expected A, got %v", ab[0])
}
- if as[1] != "B" {
- t.Errorf("Expected B, got %v", as[1])
+ if ab[1] != "B" {
+ t.Errorf("Expected B, got %v", ab[1])
}
- if as[25] != "Z" {
- t.Errorf("Expected Z, got %v", as[25])
+ if ab[25] != "Z" {
+ t.Errorf("Expected Z, got %v", ab[25])
}
}
func TestAlphas(t *testing.T) {
- as := alphas(2)
- if as[0] != "A" {
- t.Errorf("Expected A, got %v", as[0])
+ ecs := cols(2)
+ if ecs[0] != "A" {
+ t.Errorf("Expected A, got %v", ecs[0])
}
- if as[25] != "Z" {
- t.Errorf("Expected Z, got %v", as[25])
+ if ecs[25] != "Z" {
+ t.Errorf("Expected Z, got %v", ecs[25])
}
- if as[26] != "AA" {
- t.Errorf("Expected AA, got %v", as[26])
+ if ecs[26] != "AA" {
+ t.Errorf("Expected AA, got %v", ecs[26])
}
- if as[52] != "BA" {
- t.Errorf("Expected BA, got %v", as[52])
+ if ecs[52] != "BA" {
+ t.Errorf("Expected BA, got %v", ecs[52])
}
}