From 6e4a1c902f58e0a057fd23ab2276115f6d3a8f46 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 11 Nov 2019 20:55:58 +0000 Subject: struggling on with this func to manage the parsed data data structure --- reader/reader.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'reader/reader.go') 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 -- cgit v1.2.3