@@ -128,7 +128,7 @@
|
||||
"default": "Please choose"
|
||||
},
|
||||
{
|
||||
"col": "E",
|
||||
"col": "F",
|
||||
"field": "Costs",
|
||||
"type": "string",
|
||||
"default": "0"
|
||||
|
||||
@@ -43,14 +43,20 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
|
||||
for r := a.StartRow; r <= a.EndRow; r++ {
|
||||
sf := ecalc.SupplyFraction{}
|
||||
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(&sf, c.Field, cellValue)
|
||||
err = set.Field(&sf, c.Field, cellValue)
|
||||
if err != nil {
|
||||
errs = append(errs,
|
||||
fmt.Errorf("XLSXL.SupplyFraction: Sheet %d, Cell %s: %w",
|
||||
a.Sheet, axis, err))
|
||||
}
|
||||
}
|
||||
eBalance.CompanyFacts.SupplyFractions =
|
||||
append(
|
||||
|
||||
23
pkg/loader/loader_test.go
Normal file
23
pkg/loader/loader_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"testing"
|
||||
|
||||
"github.com/matryer/is"
|
||||
)
|
||||
|
||||
//go:embed test/testfile.xlsx
|
||||
var tb []byte
|
||||
|
||||
func TestXLSX(t *testing.T) {
|
||||
is := is.New(t)
|
||||
buf := bytes.NewBuffer(tb)
|
||||
got, err := XLSX(buf, nil)
|
||||
is.NoErr(err) // no error for testfile
|
||||
is.Equal(got.Version, "5.04") // version 5.04
|
||||
is.Equal(got.CompanyFacts.TotalPurchaseFromSuppliers, 10000)
|
||||
is.Equal(got.CompanyFacts.SupplyFractions[0].Costs, 500)
|
||||
is.Equal(got.CompanyFacts.SupplyFractions[0].CountryCode, "ALB")
|
||||
}
|
||||
BIN
pkg/loader/test/testfile.xlsx
Normal file
BIN
pkg/loader/test/testfile.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user