This repository has been archived by the owner on Jul 27, 2018. It is now read-only.
/
spreadsheets.go
99 lines (78 loc) · 2.08 KB
/
spreadsheets.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package export
import (
"fmt"
"time"
"github.com/andrewcharlton/school-dashboard/analysis/student"
"github.com/andrewcharlton/school-dashboard/database"
"github.com/andrewcharlton/school-dashboard/env"
"github.com/tealeg/xlsx"
)
func blankCell(row *xlsx.Row) {
row.AddCell()
}
func newBool(row *xlsx.Row, contents bool, style *xlsx.Style) {
cell := row.AddCell()
switch contents {
case true:
cell.Value = "Y"
case false:
cell.Value = "N"
}
cell.SetStyle(style)
}
func newCell(row *xlsx.Row, contents string, style *xlsx.Style) {
cell := row.AddCell()
cell.Value = contents
cell.SetStyle(style)
}
func newInt(row *xlsx.Row, contents int, style *xlsx.Style) {
cell := row.AddCell()
cell.SetInt(contents)
cell.SetStyle(style)
}
func newFloat(row *xlsx.Row, contents float64, format string, style *xlsx.Style) {
cell := row.AddCell()
cell.SetFloatWithFormat(contents, format)
cell.SetStyle(style)
}
type exportInfo struct {
Key string
Value string
}
// Produces a sheet with all of the export information held on it.
func exportInfoSheet(sheet *xlsx.Sheet, e env.Env, f database.Filter) {
d, m, y := time.Now().Date()
date, _ := e.LookupDate(f.Date)
rs, _ := e.LookupResultset(f.Resultset)
nat, _ := e.LookupNatYear(f.NatYear)
info := []exportInfo{{"Export Date: ", fmt.Sprintf("%02d-%02d-%d", d, m, y)},
{"Effective Date:", date},
{"Resultset:", rs},
{"National Data:", nat},
{"Yeargroup:", f.Year},
}
row := sheet.AddRow()
for _, i := range info {
row = sheet.AddRow()
blankCell(row)
newCell(row, i.Key, newStyle("Bold", "None", "None", "Left"))
newCell(row, i.Value, newStyle("Bold", "None", "None", "Left"))
}
sheet.SetColWidth(1, 1, 14.0)
}
// A list of student filters
var studentFilters = []string{
"Gender",
"PP",
"KS2",
"SEN",
}
// Writes the first few columns to match the student filters
func studentDetails(row *xlsx.Row, s student.Student) {
newCell(row, s.UPN, left)
newCell(row, s.Name(), left)
newCell(row, string(s.Gender), center)
newBool(row, s.PP, center)
newCell(row, s.KS2.Av, center)
newCell(row, s.SEN.Status, center)
}