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"`
Field string `json:"field"`
Type string `json:"type"`
Split string `json:"split"`
Default string `json:"default"`
}

View File

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

View File

@@ -3,6 +3,7 @@ package loader
import (
"fmt"
"io"
"strings"
"git.ecogood.org/andreas.schroepfer/excelConverter/pkg/ecalc"
"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)
cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet),
axis,
)
axis)
if err != nil {
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)
if err != nil {
errs = append(errs,
@@ -58,6 +63,10 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
a.Sheet, axis, err))
}
}
if (sf == ecalc.SupplyFraction{}) {
// do not add a empty struct
continue
}
eBalance.CompanyFacts.SupplyFractions =
append(
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++ {
ef := ecalc.EmployeesFraction{}
for _, c := range a.Cols {
axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet),
fmt.Sprintf("%s%d", c.Col, r),
)
axis)
if err != nil {
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 =
append(
@@ -85,14 +108,28 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
for r := a.StartRow; r <= a.EndRow; r++ {
is := ecalc.IndustrySector{}
for _, c := range a.Cols {
axis := fmt.Sprintf("%s%d", c.Col, r)
cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(a.Sheet),
fmt.Sprintf("%s%d", c.Col, r),
)
axis)
if err != nil {
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 =
append(