aboutsummaryrefslogtreecommitdiffstats
path: root/reader/reader.go
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-11-03 17:04:06 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2019-11-03 17:04:06 +0000
commitb86942c3eaf0ad7670b03b432f17c721c836adef (patch)
treee4f4c958c4e397b72482701754a9dce20b05041a /reader/reader.go
parentaa709070486848586937efe339ab6fd985b2c0bf (diff)
lots of stuff
Diffstat (limited to '')
-rw-r--r--reader/reader.go53
1 files changed, 49 insertions, 4 deletions
diff --git a/reader/reader.go b/reader/reader.go
index e9eabac..465f242 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "log"
"strings"
"github.com/tealeg/xlsx"
@@ -61,18 +62,62 @@ func ReadDML(path string) ([]DatamapLine, error) {
return s, nil
}
+//ExtractedCell is Data pulled from a cell
+type ExtractedCell struct {
+ cell *xlsx.Cell
+ colLidx string
+ rowLidx int
+ value string
+}
+
+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))
+ }
+ }
+ return lets
+}
+
//ReadXLSX reads an XLSX file
-func ReadXLSX(excelFileName string) {
+func ReadXLSX(excelFileName string) []ExtractedCell {
+ var out []ExtractedCell
+ alphs := alphas()
+ for _, l := range alphs {
+ fmt.Printf("Letter: %s", string(l))
+ }
xlFile, err := xlsx.OpenFile(excelFileName)
if err != nil {
fmt.Printf("Cannot open %s", excelFileName)
}
for _, sheet := range xlFile.Sheets {
- for _, row := range sheet.Rows {
- for _, cell := range row.Cells {
+ for rowLidx, row := range sheet.Rows {
+ for colLidx, cell := range row.Cells {
+ ex := ExtractedCell{
+ cell: cell,
+ colLidx: string(alphs[colLidx]),
+ rowLidx: rowLidx + 1,
+ value: cell.Value}
+ out = append(out, ex)
text := cell.String()
- fmt.Printf("Sheet: %s\nValue: %s\n", sheet.Name, text)
+ log.Printf("Sheet: %s Row: %d Col: %q Value: %s\n",
+ sheet.Name, rowLidx, alphs[colLidx], text)
}
}
}
+ return out
}