company facts simple read out of xls works
This commit is contained in:
@@ -1,56 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"os"
|
||||
|
||||
"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{},
|
||||
xf, err := os.Open("../../test/gwb-rechner_5_0_4_vollbilanz.xlsx")
|
||||
if err != nil {
|
||||
log.Fatal("cannot open file:", err)
|
||||
}
|
||||
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)
|
||||
defer xf.Close()
|
||||
eBalance, err := loader.XLSX(xf, nil)
|
||||
fmt.Printf("%s\n%#v", err, eBalance.CompanyFacts.IndustrySectors)
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
xlsx "github.com/tealeg/xlsx/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
xls, err := xlsx.OpenFile("../../test/gwb-rechner_5_0_4_vollbilanz.xlsx")
|
||||
fmt.Println("OpenFile err:", err)
|
||||
sl, err := xls.ToSlice()
|
||||
fmt.Printf("err: %v\n\n%#v", err, sl[1])
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
{
|
||||
"title": "",
|
||||
"version": "",
|
||||
"values": [
|
||||
{
|
||||
"sheet": 0,
|
||||
"cell": "",
|
||||
"type": "",
|
||||
"struct": "",
|
||||
"field": "",
|
||||
"default": ""
|
||||
}
|
||||
],
|
||||
"areas": [
|
||||
{
|
||||
"sheet": 0,
|
||||
"start_row": 0,
|
||||
"end_row": 0,
|
||||
"struct": "",
|
||||
"cols": [
|
||||
{
|
||||
"col": "",
|
||||
"field": "",
|
||||
"type": "",
|
||||
"default": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"rating": {
|
||||
"sheet": 0,
|
||||
"start_row": 0,
|
||||
"end_row": 0,
|
||||
"points_col": "",
|
||||
"max_points_col": "",
|
||||
"id_col": "",
|
||||
"short_name_col": "",
|
||||
"name_col": "",
|
||||
"estimations_col": "",
|
||||
"weight_col": "",
|
||||
"selected_by_user_col": ""
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.ecogood.org/andreas.schroepfer/excelConverter/pkg/loader"
|
||||
excelize "github.com/360EntSecGroup-Skylar/excelize/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
xFile, err := excelize.OpenFile("../../test/gwb-rechner_5_0_4_vollbilanz.xlsx")
|
||||
fmt.Println("openFile err :", err)
|
||||
sheets := xFile.GetSheetMap()
|
||||
rows, _ := xFile.GetRows(sheets[4])
|
||||
fmt.Printf("%#v", rows)
|
||||
c := loader.Conf{}
|
||||
c.Values = append(c.Values, loader.Value{})
|
||||
c.Areas = append(c.Areas, loader.Area{
|
||||
Cols: []loader.AreaCol{
|
||||
loader.AreaCol{},
|
||||
},
|
||||
})
|
||||
fd, err := os.OpenFile("conf.json", os.O_CREATE, 0777)
|
||||
fmt.Println(err)
|
||||
defer fd.Close()
|
||||
c.EncodeJSON(fd)
|
||||
}
|
||||
Reference in New Issue
Block a user