瀏覽代碼

Added ZoomScale SheetViewOption
Accessible value between 10 - 400

Used as:
xlsx.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(75))

OloloevReal 7 年之前
父節點
當前提交
b8464af086
共有 2 個文件被更改,包括 52 次插入0 次删除
  1. 13 0
      sheetview.go
  2. 39 0
      sheetview_test.go

+ 13 - 0
sheetview.go

@@ -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)

+ 39 - 0
sheetview_test.go

@@ -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
 }
 }