forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2017 Baliance. All rights reserved.
package main
import (
"fmt"
"log"
"baliance.com/gooxml/color"
"baliance.com/gooxml/schema/soo/sml"
"baliance.com/gooxml/spreadsheet"
)
func main() {
ss := spreadsheet.New()
sheet := ss.AddSheet()
hdrStyle := ss.StyleSheet.AddCellStyle()
hdrStyle.SetHorizontalAlignment(sml.ST_HorizontalAlignmentCenter)
lightGray := ss.StyleSheet.Fills().AddFill()
lightGrayPattern := lightGray.SetPatternFill()
lightGrayPattern.SetFgColor(color.LightGray)
hdrStyle.SetFill(lightGray)
hdr := sheet.AddRow()
hdrCell := hdr.AddCell()
hdrCell.SetString("Products")
hdrCell.SetStyle(hdrStyle)
hdrCell = hdr.AddCell()
hdrCell.SetString("# Sold")
hdrCell.SetStyle(hdrStyle)
for i := 0; i < 10; i++ {
row := sheet.AddRow()
cell := row.AddCell()
cell.SetString(fmt.Sprintf("Product %d", i+1))
cell = row.AddCell()
cell.SetNumber(float64(i + 1))
}
totalRow := sheet.AddRow()
totalCell := totalRow.AddCell()
totalCell = totalRow.AddCell()
totalCell.SetFormulaRaw("SUM(B2:B11)")
ss.RecalculateFormulas()
if err := ss.Validate(); err != nil {
log.Fatalf("error validating: %s", err)
}
ss.SaveToFile("formula.xlsx")
}