Added ZoomScale SheetViewOption

Accessible value between 10 - 400

Used as:
xlsx.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(75))
This commit is contained in:
OloloevReal 2018-04-15 22:56:47 +03:00
parent 2b97c3bb46
commit b8464af086
2 changed files with 52 additions and 0 deletions

View File

@ -24,6 +24,8 @@ type (
ShowGridLines bool
// ShowRowColHeaders is a SheetViewOption.
ShowRowColHeaders bool
// ZoomScale is a SheetViewOption.
ZoomScale float64
/* TODO
// ShowWhiteSpace is a SheetViewOption.
ShowWhiteSpace bool
@ -76,6 +78,17 @@ func (o *ShowRowColHeaders) getSheetViewOption(view *xlsxSheetView) {
*o = ShowRowColHeaders(defaultTrue(view.ShowRowColHeaders)) // Excel default: true
}
func (o ZoomScale) setSheetViewOption(view *xlsxSheetView) {
//This attribute is restricted to values ranging from 10 to 400.
if float64(o) >= 10 && float64(o) <= 400 {
view.ZoomScale = float64(o)
}
}
func (o *ZoomScale) getSheetViewOption(view *xlsxSheetView) {
*o = ZoomScale(view.ZoomScale)
}
// getSheetView returns the SheetView object
func (f *File) getSheetView(sheetName string, viewIndex int) (*xlsxSheetView, error) {
xlsx := f.workSheetReader(sheetName)

View File

@ -39,10 +39,45 @@ func ExampleFile_SetSheetViewOptions() {
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() {
@ -55,6 +90,7 @@ func ExampleFile_GetSheetViewOptions() {
showFormulas excelize.ShowFormulas
showGridLines excelize.ShowGridLines
showRowColHeaders excelize.ShowRowColHeaders
zoomScale excelize.ZoomScale
)
if err := xl.GetSheetViewOptions(sheet, 0,
@ -63,6 +99,7 @@ func ExampleFile_GetSheetViewOptions() {
&showFormulas,
&showGridLines,
&showRowColHeaders,
&zoomScale,
); err != nil {
panic(err)
}
@ -73,6 +110,7 @@ func ExampleFile_GetSheetViewOptions() {
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)
@ -92,6 +130,7 @@ func ExampleFile_GetSheetViewOptions() {
// - showFormulas: false
// - showGridLines: true
// - showRowColHeaders: true
// - zoomScale: 0
// After change:
// - showGridLines: false
}