feat: adds overview sheet with chart
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Marvin Preuss 2023-04-12 11:11:29 +00:00
parent 4e80f25d32
commit 9bf0b05ec6

View File

@ -119,13 +119,15 @@ func Create(out, dir string) error {
} }
} }
for cat, item := range c { if _, err := f.NewSheet("Overview"); err != nil {
if err := f.DeleteSheet("Sheet1"); err != nil { return fmt.Errorf("failed to add overview sheet: %w", err)
return fmt.Errorf("failed to remove default sheet: %w", err) }
}
_, err := f.NewSheet(cat) catLength := 0
if err != nil {
for cat, item := range c {
if _, err := f.NewSheet(cat); err != nil {
return fmt.Errorf("failed to create new sheet: %w", err) return fmt.Errorf("failed to create new sheet: %w", err)
} }
@ -134,24 +136,43 @@ func Create(out, dir string) error {
m[i.Company] += i.Value m[i.Company] += i.Value
} }
length := 0 valueLength := 0
for k, v := range m { for k, v := range m {
if err := f.SetCellStr(cat, fmt.Sprintf("A%d", length+1), k); err != nil { if err := f.SetCellStr(cat, fmt.Sprintf("A%d", valueLength+1), k); err != nil {
return fmt.Errorf("failed to set cell: %w", err) return fmt.Errorf("failed to set cell: %w", err)
} }
if err := f.SetCellFloat(cat, fmt.Sprintf("B%d", length+1), v, 2, 64); err != nil { if err := f.SetCellFloat(cat, fmt.Sprintf("B%d", valueLength+1), v, 2, 64); err != nil {
return fmt.Errorf("failed to set cell: %w", err) return fmt.Errorf("failed to set cell: %w", err)
} }
length += 1 valueLength += 1
} }
if err := createCategoryChart(cat, length, f); err != nil { if err := createCategoryChart(cat, valueLength, f); err != nil {
return fmt.Errorf("failed to create category chart: %w", err) return fmt.Errorf("failed to create category chart: %w", err)
} }
// Add to overview.
if err := f.SetCellStr("Overview", fmt.Sprintf("A%d", catLength+1), cat); err != nil {
return fmt.Errorf("failed to set category to overview: %w", err)
}
if err := f.SetCellFormula("Overview", fmt.Sprintf("B%d", catLength+1), fmt.Sprintf("=SUM(%s!B1:B%d)", cat, valueLength)); err != nil {
return fmt.Errorf("failed to set sum to overview: %w", err)
}
if err := createCategoryChart("Overview", catLength+1, f); err != nil {
return fmt.Errorf("failed to create overview chat: %w", err)
}
catLength += 1
}
if err := f.DeleteSheet("Sheet1"); err != nil {
return fmt.Errorf("failed to remove default sheet: %w", err)
} }
if err := f.SaveAs(out); err != nil { if err := f.SaveAs(out); err != nil {