diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-12 09:06:59 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2019-11-12 09:06:59 +0000 |
commit | a1aae604cf128826ec7a5485c197c05528edc800 (patch) | |
tree | dffa4410a6202a520fb5afcc1b94fdcf316cd29e /reader/reader.go | |
parent | 6e4a1c902f58e0a057fd23ab2276115f6d3a8f46 (diff) |
first passing test after parsing XLSX data into decent data structure
Diffstat (limited to '')
-rw-r--r-- | reader/reader.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/reader/reader.go b/reader/reader.go index be9b5bc..c24adc2 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -116,45 +116,45 @@ 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 +type ( + SheetData map[string]ExtractedCell + FileData map[string]SheetData +) -func ReadXLSToMap(dm string, tm string) map[string][]cellrefVal { - var out map[string][]cellrefVal +func ReadXLSToMap(dm string, tm string) FileData { // open the files excelData, err := xlsx.OpenFile(tm) if err != nil { - fmt.Printf("Cannot open %v", excelData) + log.Fatalf("Cannot open %v", excelData) } dmlData, err := ReadDML(dm) if err != nil { - fmt.Errorf("Cannot read datamap file %v", dm) + log.Fatalf("Cannot read datamap file %v", dm) } + sheetNames := getSheetNames(dmlData) + + output := make(FileData, len(sheetNames)) + // get the data for _, sheet := range excelData.Sheets { - sheetNames := getSheetNames(dmlData) - sheetData := make(map[string][]cellrefVal, len(sheetNames)) - var cellDataList []map[string]ExtractedCell + data := make(SheetData) 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) + data[cellref] = ex } + output[sheet.Name] = data } } - return out + return output } //ReadXLSX reads an XLSX file |