获取工作表视图属性

  1. func (f *File) GetSheetViewOptions(name string, viewIndex int, opts ...SheetViewOptionPtr) error

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

可选视图参数类型
DefaultGridColorbool
RightToLeftbool
ShowFormulasbool
ShowGridLinesbool
ShowRowColHeadersbool
  • 例1,获取名为 Sheet1 的工作表上最后一个视图的网格线属性设置:
  1. var showGridLines excelize.ShowGridLines
  2. err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines)
  • 例2:
  1. xl := excelize.NewFile()
  2. const sheet = "Sheet1"
  3. var (
  4. defaultGridColor excelize.DefaultGridColor
  5. rightToLeft excelize.RightToLeft
  6. showFormulas excelize.ShowFormulas
  7. showGridLines excelize.ShowGridLines
  8. showRowColHeaders excelize.ShowRowColHeaders
  9. zoomScale excelize.ZoomScale
  10. topLeftCell excelize.TopLeftCell
  11. )
  12. if err := xl.GetSheetViewOptions(sheet, 0,
  13. &defaultGridColor,
  14. &rightToLeft,
  15. &showFormulas,
  16. &showGridLines,
  17. &showRowColHeaders,
  18. &zoomScale,
  19. &topLeftCell,
  20. ); err != nil {
  21. panic(err)
  22. }
  23. fmt.Println("Default:")
  24. fmt.Println("- defaultGridColor:", defaultGridColor)
  25. fmt.Println("- rightToLeft:", rightToLeft)
  26. fmt.Println("- showFormulas:", showFormulas)
  27. fmt.Println("- showGridLines:", showGridLines)
  28. fmt.Println("- showRowColHeaders:", showRowColHeaders)
  29. fmt.Println("- zoomScale:", zoomScale)
  30. fmt.Println("- topLeftCell:", `"`+topLeftCell+`"`)
  31. if err := xl.SetSheetViewOptions(sheet, 0, excelize.TopLeftCell("B2")); err != nil {
  32. panic(err)
  33. }
  34. if err := xl.GetSheetViewOptions(sheet, 0, &topLeftCell); err != nil {
  35. panic(err)
  36. }
  37. if err := xl.SetSheetViewOptions(sheet, 0, excelize.ShowGridLines(false)); err != nil {
  38. panic(err)
  39. }
  40. if err := xl.GetSheetViewOptions(sheet, 0, &showGridLines); err != nil {
  41. panic(err)
  42. }
  43. fmt.Println("After change:")
  44. fmt.Println("- showGridLines:", showGridLines)
  45. fmt.Println("- topLeftCell:", topLeftCell)

得到输出:

  1. Default:
  2. - defaultGridColor: true
  3. - rightToLeft: false
  4. - showFormulas: false
  5. - showGridLines: true
  6. - showRowColHeaders: true
  7. - zoomScale: 0
  8. - topLeftCell: ""
  9. After change:
  10. - showGridLines: false
  11. - topLeftCell: B2