设置工作表视图属性

  1. func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error

根据给定的工作表名称、视图索引和视图参数设置工作表视图属性,viewIndex 可以是负数,如果是这样,则向后计数(-1 代表最后一个视图)。

可选视图参数类型
DefaultGridColorbool
ShowFormulasbool
ShowGridLinesbool
ShowRowColHeadersbool
ShowZerosbool
RightToLeftbool
ShowRulerbool
Viewstring
TopLeftCellstring
ZoomScalefloat64
  • 例1:
  1. err = f.SetSheetViewOptions("Sheet1", -1, ShowGridLines(false))
  • 例2:
  1. f := excelize.NewFile()
  2. const sheet = "Sheet1"
  3. if err := f.SetSheetViewOptions(sheet, 0,
  4. excelize.DefaultGridColor(false),
  5. excelize.ShowFormulas(true),
  6. excelize.ShowGridLines(true),
  7. excelize.ShowRowColHeaders(true),
  8. excelize.RightToLeft(false),
  9. excelize.ShowRuler(false),
  10. excelize.View("pageLayout"),
  11. excelize.TopLeftCell("C3"),
  12. excelize.ZoomScale(80),
  13. ); err != nil {
  14. fmt.Println(err)
  15. }
  16. var zoomScale ZoomScale
  17. fmt.Println("Default:")
  18. fmt.Println("- zoomScale: 80")
  19. if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
  20. fmt.Println(err)
  21. }
  22. if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
  23. fmt.Println(err)
  24. }
  25. fmt.Println("Used out of range value:")
  26. fmt.Println("- zoomScale:", zoomScale)
  27. if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
  28. fmt.Println(err)
  29. }
  30. if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
  31. fmt.Println(err)
  32. }
  33. fmt.Println("Used correct value:")
  34. fmt.Println("- zoomScale:", zoomScale)

得到输出:

  1. Default:
  2. - zoomScale: 80
  3. Used out of range value:
  4. - zoomScale: 80
  5. Used correct value:
  6. - zoomScale: 123