Merge pull request #211 from OloloevReal/master

Added ZoomScale SheetViewOption
This commit is contained in:
xuri 2018-05-07 15:50:11 +08:00 committed by GitHub
commit 761d47f45a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -24,6 +24,8 @@ type (
ShowGridLines bool ShowGridLines bool
// ShowRowColHeaders is a SheetViewOption. // ShowRowColHeaders is a SheetViewOption.
ShowRowColHeaders bool ShowRowColHeaders bool
// ZoomScale is a SheetViewOption.
ZoomScale float64
/* TODO /* TODO
// ShowWhiteSpace is a SheetViewOption. // ShowWhiteSpace is a SheetViewOption.
ShowWhiteSpace bool ShowWhiteSpace bool
@ -76,6 +78,17 @@ func (o *ShowRowColHeaders) getSheetViewOption(view *xlsxSheetView) {
*o = ShowRowColHeaders(defaultTrue(view.ShowRowColHeaders)) // Excel default: true *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 // getSheetView returns the SheetView object
func (f *File) getSheetView(sheetName string, viewIndex int) (*xlsxSheetView, error) { func (f *File) getSheetView(sheetName string, viewIndex int) (*xlsxSheetView, error) {
xlsx := f.workSheetReader(sheetName) xlsx := f.workSheetReader(sheetName)

View File

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