diff --git a/cmd/conv/default.json b/cmd/conv/default.json new file mode 100644 index 0000000..3ee9615 --- /dev/null +++ b/cmd/conv/default.json @@ -0,0 +1,198 @@ +{ + "title": "Good Balance Calculator", + "version": "5.04", + "values": [ + { + "sheet": 2, + "cell": "C7", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalPurchaseFromSuppliers", + "default": "" + }, + { + "sheet": 2, + "cell": "C27", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalStaffCosts", + "default": "" + }, + { + "sheet": 2, + "cell": "C18", + "type": "int", + "struct": "CompanyFacts", + "field": "Profit", + "default": "" + }, + { + "sheet": 2, + "cell": "C19", + "type": "int", + "struct": "CompanyFacts", + "field": "FinancialCosts", + "default": "" + }, + { + "sheet": 2, + "cell": "C20", + "type": "int", + "struct": "CompanyFacts", + "field": "IncomeFromFinancialInvestments", + "default": "" + }, + { + "sheet": 2, + "cell": "C22", + "type": "int", + "struct": "CompanyFacts", + "field": "AdditionsToFixedAssets", + "default": "" + }, + { + "sheet": 2, + "cell": "C37", + "type": "int", + "struct": "CompanyFacts", + "field": "Turnover", + "default": "" + }, + { + "sheet": 2, + "cell": "C21", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalAssets", + "default": "" + }, + { + "sheet": 2, + "cell": "C23", + "type": "int", + "struct": "CompanyFacts", + "field": "FinancialAssetsAndCashBalance", + "default": "" + }, + { + "sheet": 2, + "cell": "C26", + "type": "int", + "struct": "CompanyFacts", + "field": "NumberOfEmployees", + "default": "" + }, + { + "sheet": 2, + "cell": "C24", + "type": "bool", + "struct": "CompanyFacts", + "field": "HasCanteen", + "default": "" + }, + { + "sheet": 2, + "cell": "C38", + "type": "bool", + "struct": "CompanyFacts", + "field": "IsB2B", + "default": "" + }, + { + "sheet": 2, + "cell": "C33", + "type": "int", + "struct": "CompanyFacts", + "field": "AverageJourneyToWorkForStaffInKm", + "default": "" + } + ], + "areas": [ + { + "sheet": 2, + "start_row": 10, + "end_row": 14, + "struct": "SupplyFraction", + "cols": [ + { + "col": "B", + "field": "IndustryCode", + "type": "string", + "default": "" + }, + { + "col": "D", + "field": "CountryCode", + "type": "string", + "default": "" + }, + { + "col": "E", + "field": "Costs", + "type": "string", + "default": "" + } + ] + }, + { + "sheet": 2, + "start_row": 30, + "end_row": 32, + "struct": "EmployeesFraction", + "cols": [ + { + "col": "B", + "field": "CountryCode", + "type": "string", + "default": "" + }, + { + "col": "D", + "field": "Percentage", + "type": "float32", + "default": "" + } + ] + }, + { + "sheet": 2, + "start_row": 41, + "end_row": 43, + "struct": "IndustrySector", + "cols": [ + { + "col": "B", + "field": "IndustryCode", + "type": "string", + "default": "" + }, + { + "col": "C", + "field": "Description", + "type": "string", + "default": "" + }, + { + "col": "D", + "field": "AmountOfTotalTurnover", + "type": "int", + "default": "" + } + ] + } + ], + "rating": { + "sheet": 3, + "start_row": 9, + "end_row": 93, + "points_col": "I", + "max_points_col": "J", + "id_col": "", + "short_name_col": "B", + "name_col": "C", + "estimations_col": "H", + "weight_col": "D", + "selected_by_user_col": "N" + } + } + \ No newline at end of file diff --git a/cmd/conv/main.go b/cmd/conv/main.go new file mode 100644 index 0000000..063baed --- /dev/null +++ b/cmd/conv/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "bytes" + _ "embed" + "fmt" + "log" + "strconv" + + "git.ecogood.org/andreas.schroepfer/excelConverter/pkg/ecalc" + "git.ecogood.org/andreas.schroepfer/excelConverter/pkg/loader" + "git.ecogood.org/andreas.schroepfer/excelConverter/pkg/set" + excelize "github.com/360EntSecGroup-Skylar/excelize/v2" +) + +//go:embed default.json +var defaultConf []byte + +func main() { + buf := bytes.NewBuffer(defaultConf) + conf := &loader.Conf{} + err := conf.DecodeJSON(buf) + //fmt.Println(err, conf) + + eBalance := ecalc.Ecalc{ + CompanyFacts: ecalc.CompanyFacts{}, + } + xFile, err := excelize.OpenFile("../../test/gwb-rechner_5_0_4_vollbilanz.xlsx") + fmt.Println("openFile err :", err) + //sheets := make(map[int]) + for _, v := range conf.Values { + cellValue, err := xFile.GetCellValue( + xFile.GetSheetName(v.Sheet), + v.Cell, + ) + if err != nil { + log.Println("error", err) + } + var inValue interface{} + switch v.Struct { + case "CompanyFacts": + switch v.Type { + case "int": + inValue, err = strconv.Atoi(cellValue) + if err != nil { + fmt.Println(xFile.GetSheetName(v.Sheet)) + fmt.Println("err ATOI", err) + } + default: + inValue = cellValue + } + set.Field(&eBalance.CompanyFacts, v.Field, inValue) + } + } + fmt.Printf("%#v", eBalance) +} diff --git a/pkg/loader/conf.go b/pkg/loader/conf.go index e39cf1c..33092b9 100644 --- a/pkg/loader/conf.go +++ b/pkg/loader/conf.go @@ -68,3 +68,10 @@ func (c Conf) EncodeJSON(w io.Writer) error { enc.SetIndent("", " ") return enc.Encode(c) } + +// DecodeJSON writes the configuration from the reader into +// the pointer of the conf +func (c *Conf) DecodeJSON(r io.Reader) error { + dec := json.NewDecoder(r) + return dec.Decode(c) +} diff --git a/test/gwb-rechner_5_0_4_vollbilanz.xlsx b/test/gwb-rechner_5_0_4_vollbilanz.xlsx index e3431bf..beb35dd 100644 Binary files a/test/gwb-rechner_5_0_4_vollbilanz.xlsx and b/test/gwb-rechner_5_0_4_vollbilanz.xlsx differ