设置工作表视图属性

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

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

可选视图参数类型
DefaultGridColorbool
RightToLeftbool
ShowFormulasbool
ShowGridLinesbool
ShowRowColHeadersbool
ZoomScalefloat64
TopLeftCellstring
  • 例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.RightToLeft(false),
  6. excelize.ShowFormulas(true),
  7. excelize.ShowGridLines(true),
  8. excelize.ShowRowColHeaders(true),
  9. excelize.ZoomScale(80),
  10. excelize.TopLeftCell("C3"),
  11. ); err != nil {
  12. fmt.Println(err)
  13. }
  14. var zoomScale excelize.ZoomScale
  15. fmt.Println("Default:")
  16. fmt.Println("- zoomScale: 80")
  17. if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
  18. fmt.Println(err)
  19. }
  20. if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
  21. fmt.Println(err)
  22. }
  23. fmt.Println("Used out of range value:")
  24. fmt.Println("- zoomScale:", zoomScale)
  25. if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
  26. fmt.Println(err)
  27. }
  28. if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
  29. fmt.Println(err)
  30. }
  31. fmt.Println("Used correct value:")
  32. 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