Skip to content

Commit b8464af

Browse files
committed
Added ZoomScale SheetViewOption
Accessible value between 10 - 400 Used as: xlsx.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(75))
1 parent 2b97c3b commit b8464af

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

sheetview.go

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type (
2424
ShowGridLines bool
2525
// ShowRowColHeaders is a SheetViewOption.
2626
ShowRowColHeaders bool
27+
// ZoomScale is a SheetViewOption.
28+
ZoomScale float64
2729
/* TODO
2830
// ShowWhiteSpace is a SheetViewOption.
2931
ShowWhiteSpace bool
@@ -76,6 +78,17 @@ func (o *ShowRowColHeaders) getSheetViewOption(view *xlsxSheetView) {
7678
*o = ShowRowColHeaders(defaultTrue(view.ShowRowColHeaders)) // Excel default: true
7779
}
7880

81+
func (o ZoomScale) setSheetViewOption(view *xlsxSheetView) {
82+
//This attribute is restricted to values ranging from 10 to 400.
83+
if float64(o) >= 10 && float64(o) <= 400 {
84+
view.ZoomScale = float64(o)
85+
}
86+
}
87+
88+
func (o *ZoomScale) getSheetViewOption(view *xlsxSheetView) {
89+
*o = ZoomScale(view.ZoomScale)
90+
}
91+
7992
// getSheetView returns the SheetView object
8093
func (f *File) getSheetView(sheetName string, viewIndex int) (*xlsxSheetView, error) {
8194
xlsx := f.workSheetReader(sheetName)

sheetview_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,45 @@ func ExampleFile_SetSheetViewOptions() {
3939
excelize.ShowFormulas(true),
4040
excelize.ShowGridLines(true),
4141
excelize.ShowRowColHeaders(true),
42+
excelize.ZoomScale(80),
4243
); err != nil {
4344
panic(err)
4445
}
46+
47+
var zoomScale excelize.ZoomScale
48+
fmt.Println("Default:")
49+
fmt.Println("- zoomScale: 80")
50+
51+
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
52+
panic(err)
53+
}
54+
55+
if err := xl.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
56+
panic(err)
57+
}
58+
59+
fmt.Println("Used out of range value:")
60+
fmt.Println("- zoomScale:", zoomScale)
61+
62+
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
63+
panic(err)
64+
}
65+
66+
if err := xl.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
67+
panic(err)
68+
}
69+
70+
fmt.Println("Used correct value:")
71+
fmt.Println("- zoomScale:", zoomScale)
72+
4573
// Output:
74+
// Default:
75+
// - zoomScale: 80
76+
// Used out of range value:
77+
// - zoomScale: 80
78+
// Used correct value:
79+
// - zoomScale: 123
80+
4681
}
4782

4883
func ExampleFile_GetSheetViewOptions() {
@@ -55,6 +90,7 @@ func ExampleFile_GetSheetViewOptions() {
5590
showFormulas excelize.ShowFormulas
5691
showGridLines excelize.ShowGridLines
5792
showRowColHeaders excelize.ShowRowColHeaders
93+
zoomScale excelize.ZoomScale
5894
)
5995

6096
if err := xl.GetSheetViewOptions(sheet, 0,
@@ -63,6 +99,7 @@ func ExampleFile_GetSheetViewOptions() {
6399
&showFormulas,
64100
&showGridLines,
65101
&showRowColHeaders,
102+
&zoomScale,
66103
); err != nil {
67104
panic(err)
68105
}
@@ -73,6 +110,7 @@ func ExampleFile_GetSheetViewOptions() {
73110
fmt.Println("- showFormulas:", showFormulas)
74111
fmt.Println("- showGridLines:", showGridLines)
75112
fmt.Println("- showRowColHeaders:", showRowColHeaders)
113+
fmt.Println("- zoomScale:", zoomScale)
76114

77115
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ShowGridLines(false)); err != nil {
78116
panic(err)
@@ -92,6 +130,7 @@ func ExampleFile_GetSheetViewOptions() {
92130
// - showFormulas: false
93131
// - showGridLines: true
94132
// - showRowColHeaders: true
133+
// - zoomScale: 0
95134
// After change:
96135
// - showGridLines: false
97136
}

0 commit comments

Comments
 (0)