-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel.go
45 lines (37 loc) · 992 Bytes
/
excel.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
package excel
import (
"time"
"github.com/tealeg/xlsx"
)
func BuildExcelHeaders(sheet *xlsx.Sheet, headers []string) {
// header row
header := sheet.AddRow()
for k := range headers {
cell := header.AddCell()
cell.Value = headers[k]
}
}
func AddCellString(row *xlsx.Row, value string) {
cell := row.AddCell()
cell.Value = value
}
func AddCellMoney(row *xlsx.Row, value float64) {
cell := row.AddCell()
cell.SetFloatWithFormat(value, "_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)")
}
func AddCellPercent(row *xlsx.Row, value float64) {
cell := row.AddCell()
cell.SetFloatWithFormat(value, "0.00%")
}
func AddCellInteger(row *xlsx.Row, value int64) {
cell := row.AddCell()
cell.SetInt64(value)
}
func AddCellDate(row *xlsx.Row, value time.Time) {
timeLocationUTC, _ := time.LoadLocation("UTC")
cell := row.AddCell()
cell.SetDateWithOptions(value, xlsx.DateTimeOptions{
Location: timeLocationUTC,
ExcelTimeFormat: "mm-dd-yy",
})
}