forked from qax-os/excelize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheetview_test.go
128 lines (111 loc) · 3.15 KB
/
sheetview_test.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package excelize_test
import (
"fmt"
"testing"
"github.com/360EntSecGroup-Skylar/excelize"
)
var _ = []excelize.SheetViewOption{
excelize.DefaultGridColor(true),
excelize.RightToLeft(false),
excelize.ShowFormulas(false),
excelize.ShowGridLines(true),
excelize.ShowRowColHeaders(true),
// SheetViewOptionPtr are also SheetViewOption
new(excelize.DefaultGridColor),
new(excelize.RightToLeft),
new(excelize.ShowFormulas),
new(excelize.ShowGridLines),
new(excelize.ShowRowColHeaders),
}
var _ = []excelize.SheetViewOptionPtr{
(*excelize.DefaultGridColor)(nil),
(*excelize.RightToLeft)(nil),
(*excelize.ShowFormulas)(nil),
(*excelize.ShowGridLines)(nil),
(*excelize.ShowRowColHeaders)(nil),
}
func ExampleFile_SetSheetViewOptions() {
xl := excelize.NewFile()
const sheet = "Sheet1"
if err := xl.SetSheetViewOptions(sheet, 0,
excelize.DefaultGridColor(false),
excelize.RightToLeft(false),
excelize.ShowFormulas(true),
excelize.ShowGridLines(true),
excelize.ShowRowColHeaders(true),
); err != nil {
panic(err)
}
// Output:
}
func ExampleFile_GetSheetViewOptions() {
xl := excelize.NewFile()
const sheet = "Sheet1"
var (
defaultGridColor excelize.DefaultGridColor
rightToLeft excelize.RightToLeft
showFormulas excelize.ShowFormulas
showGridLines excelize.ShowGridLines
showRowColHeaders excelize.ShowRowColHeaders
)
if err := xl.GetSheetViewOptions(sheet, 0,
&defaultGridColor,
&rightToLeft,
&showFormulas,
&showGridLines,
&showRowColHeaders,
); err != nil {
panic(err)
}
fmt.Println("Default:")
fmt.Println("- defaultGridColor:", defaultGridColor)
fmt.Println("- rightToLeft:", rightToLeft)
fmt.Println("- showFormulas:", showFormulas)
fmt.Println("- showGridLines:", showGridLines)
fmt.Println("- showRowColHeaders:", showRowColHeaders)
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ShowGridLines(false)); err != nil {
panic(err)
}
if err := xl.GetSheetViewOptions(sheet, 0, &showGridLines); err != nil {
panic(err)
}
fmt.Println("After change:")
fmt.Println("- showGridLines:", showGridLines)
// Output:
// Default:
// - defaultGridColor: true
// - rightToLeft: false
// - showFormulas: false
// - showGridLines: true
// - showRowColHeaders: true
// After change:
// - showGridLines: false
}
func TestSheetViewOptionsErrors(t *testing.T) {
xl := excelize.NewFile()
const sheet = "Sheet1"
if err := xl.GetSheetViewOptions(sheet, 0); err != nil {
t.Errorf("Unexpected error: %s", err)
}
if err := xl.GetSheetViewOptions(sheet, -1); err != nil {
t.Errorf("Unexpected error: %s", err)
}
if err := xl.GetSheetViewOptions(sheet, 1); err == nil {
t.Error("Error expected but got nil")
}
if err := xl.GetSheetViewOptions(sheet, -2); err == nil {
t.Error("Error expected but got nil")
}
if err := xl.SetSheetViewOptions(sheet, 0); err != nil {
t.Errorf("Unexpected error: %s", err)
}
if err := xl.SetSheetViewOptions(sheet, -1); err != nil {
t.Errorf("Unexpected error: %s", err)
}
if err := xl.SetSheetViewOptions(sheet, 1); err == nil {
t.Error("Error expected but got nil")
}
if err := xl.SetSheetViewOptions(sheet, -2); err == nil {
t.Error("Error expected but got nil")
}
}