This commit is contained in:
Andreas Schröpfer
2021-03-01 20:50:02 +01:00
parent 7270660f2c
commit cef519e3b6
3 changed files with 51 additions and 9 deletions

View File

@@ -75,6 +75,7 @@ type AreaCol struct {
Col string `json:"col"` Col string `json:"col"`
Field string `json:"field"` Field string `json:"field"`
Type string `json:"type"` Type string `json:"type"`
Split string `json:"split"`
Default string `json:"default"` Default string `json:"default"`
} }

View File

@@ -119,12 +119,14 @@
"col": "B", "col": "B",
"field": "IndustryCode", "field": "IndustryCode",
"type": "string", "type": "string",
"split": " ",
"default": "Please choose" "default": "Please choose"
}, },
{ {
"col": "D", "col": "D",
"field": "CountryCode", "field": "CountryCode",
"type": "string", "type": "string",
"split": " ",
"default": "Please choose" "default": "Please choose"
}, },
{ {
@@ -145,6 +147,7 @@
"col": "B", "col": "B",
"field": "CountryCode", "field": "CountryCode",
"type": "string", "type": "string",
"split": " ",
"default": "Please choose" "default": "Please choose"
}, },
{ {
@@ -165,7 +168,8 @@
"col": "B", "col": "B",
"field": "IndustryCode", "field": "IndustryCode",
"type": "string", "type": "string",
"default": "Please choose" "split": " ",
"default": "Please choose"
}, },
{ {
"col": "C", "col": "C",

View File

@@ -3,6 +3,7 @@ package loader
import ( import (
"fmt" "fmt"
"io" "io"
"strings"
"git.ecogood.org/andreas.schroepfer/excelConverter/pkg/ecalc" "git.ecogood.org/andreas.schroepfer/excelConverter/pkg/ecalc"
"git.ecogood.org/andreas.schroepfer/excelConverter/pkg/set" "git.ecogood.org/andreas.schroepfer/excelConverter/pkg/set"
@@ -46,11 +47,15 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
axis := fmt.Sprintf("%s%d", c.Col, r) axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue( cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet), xFile.GetSheetName(a.Sheet),
axis, axis)
)
if err != nil { if err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
if cellValue == c.Default {
continue
} else if c.Split != "" {
cellValue = strings.Split(cellValue, c.Split)[0]
}
err = set.Field(&sf, c.Field, cellValue) err = set.Field(&sf, c.Field, cellValue)
if err != nil { if err != nil {
errs = append(errs, errs = append(errs,
@@ -58,6 +63,10 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
a.Sheet, axis, err)) a.Sheet, axis, err))
} }
} }
if (sf == ecalc.SupplyFraction{}) {
// do not add a empty struct
continue
}
eBalance.CompanyFacts.SupplyFractions = eBalance.CompanyFacts.SupplyFractions =
append( append(
eBalance.CompanyFacts.SupplyFractions, eBalance.CompanyFacts.SupplyFractions,
@@ -67,14 +76,28 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
for r := a.StartRow; r <= a.EndRow; r++ { for r := a.StartRow; r <= a.EndRow; r++ {
ef := ecalc.EmployeesFraction{} ef := ecalc.EmployeesFraction{}
for _, c := range a.Cols { for _, c := range a.Cols {
axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue( cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet), xFile.GetSheetName(a.Sheet),
fmt.Sprintf("%s%d", c.Col, r), axis)
)
if err != nil { if err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
set.Field(&ef, c.Field, cellValue) if cellValue == c.Default {
continue
} else if c.Split != "" {
cellValue = strings.Split(cellValue, c.Split)[0]
}
err = set.Field(&ef, c.Field, cellValue)
if err != nil {
errs = append(errs,
fmt.Errorf("XLSXL.EmployeesFraction: Sheet %d, Cell %s: %w",
a.Sheet, axis, err))
}
}
if (ef == ecalc.EmployeesFraction{}) {
// do not add a empty struct
continue
} }
eBalance.CompanyFacts.EmployeesFractions = eBalance.CompanyFacts.EmployeesFractions =
append( append(
@@ -85,14 +108,28 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
for r := a.StartRow; r <= a.EndRow; r++ { for r := a.StartRow; r <= a.EndRow; r++ {
is := ecalc.IndustrySector{} is := ecalc.IndustrySector{}
for _, c := range a.Cols { for _, c := range a.Cols {
axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue( cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet), xFile.GetSheetName(a.Sheet),
fmt.Sprintf("%s%d", c.Col, r), axis)
)
if err != nil { if err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
set.Field(&is, c.Field, cellValue) if cellValue == c.Default {
continue
} else if c.Split != "" {
cellValue = strings.Split(cellValue, c.Split)[0]
}
err = set.Field(&is, c.Field, cellValue)
if err != nil {
errs = append(errs,
fmt.Errorf("XLSXL.IndustrySector: Sheet %d, Cell %s: %w",
a.Sheet, axis, err))
}
}
if (is == ecalc.IndustrySector{}) {
// do not add a empty struct
continue
} }
eBalance.CompanyFacts.IndustrySectors = eBalance.CompanyFacts.IndustrySectors =
append( append(