This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
forked from qax-os/excelize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheetview_test.go
167 lines (141 loc) · 4.02 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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),
excelize.ZoomScale(80),
); err != nil {
panic(err)
}
var zoomScale excelize.ZoomScale
fmt.Println("Default:")
fmt.Println("- zoomScale: 80")
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
panic(err)
}
if err := xl.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
panic(err)
}
fmt.Println("Used out of range value:")
fmt.Println("- zoomScale:", zoomScale)
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
panic(err)
}
if err := xl.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
panic(err)
}
fmt.Println("Used correct value:")
fmt.Println("- zoomScale:", zoomScale)
// Output:
// Default:
// - zoomScale: 80
// Used out of range value:
// - zoomScale: 80
// Used correct value:
// - zoomScale: 123
}
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
zoomScale excelize.ZoomScale
)
if err := xl.GetSheetViewOptions(sheet, 0,
&defaultGridColor,
&rightToLeft,
&showFormulas,
&showGridLines,
&showRowColHeaders,
&zoomScale,
); 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)
fmt.Println("- zoomScale:", zoomScale)
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
// - zoomScale: 0
// 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")
}
}