aboutsummaryrefslogtreecommitdiffstats
path: root/reader/reader.go
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-11-11 20:55:58 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2019-11-11 20:55:58 +0000
commit6e4a1c902f58e0a057fd23ab2276115f6d3a8f46 (patch)
tree39c4dc2e8ebf932c601893e3a476329d4e420553 /reader/reader.go
parent5a9b2ea3b312134dd7f8435d98b2f85341ba121e (diff)
struggling on with this func to manage the parsed data data structure
Diffstat (limited to 'reader/reader.go')
-rw-r--r--reader/reader.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/reader/reader.go b/reader/reader.go
index 5357672..be9b5bc 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -116,6 +116,47 @@ func cols(n int) []string {
return out
}
+// cellrefVal is a map of the cellref to the cell data
+// as provided by the xlsx package
+type cellrefVal map[string]ExtractedCell
+
+func ReadXLSToMap(dm string, tm string) map[string][]cellrefVal {
+ var out map[string][]cellrefVal
+
+ // open the files
+ excelData, err := xlsx.OpenFile(tm)
+ if err != nil {
+ fmt.Printf("Cannot open %v", excelData)
+ }
+
+ dmlData, err := ReadDML(dm)
+ if err != nil {
+ fmt.Errorf("Cannot read datamap file %v", dm)
+ }
+
+ // get the data
+ for _, sheet := range excelData.Sheets {
+ sheetNames := getSheetNames(dmlData)
+ sheetData := make(map[string][]cellrefVal, len(sheetNames))
+ var cellDataList []map[string]ExtractedCell
+ for rowLidx, row := range sheet.Rows {
+ for colLidx, cell := range row.Cells {
+ cellData := make(map[string]ExtractedCell)
+ ex := ExtractedCell{
+ cell: cell,
+ colL: colstream[colLidx],
+ rowLidx: rowLidx + 1,
+ value: cell.Value}
+ cellref := fmt.Sprintf("%s%d", ex.colL, ex.rowLidx)
+ cellData[cellref] = ex
+ cellDataList = append(cellDataList, cellData)
+ sheetData[sheet.Name] = append(sheetData[sheet.Name], cellData)
+ }
+ }
+ }
+ return out
+}
+
//ReadXLSX reads an XLSX file
func ReadXLSX(fn string) []ExtractedCell {
var out []ExtractedCell