设置工作表视图属性
func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error
根据给定的工作表名称、视图索引和视图参数设置工作表视图属性,viewIndex
可以是负数,如果是这样,则向后计数(-1
代表最后一个视图)。
可选视图参数 | 类型 |
---|---|
DefaultGridColor | bool |
ShowFormulas | bool |
ShowGridLines | bool |
ShowRowColHeaders | bool |
ShowZeros | bool |
RightToLeft | bool |
ShowRuler | bool |
View | string |
TopLeftCell | string |
ZoomScale | float64 |
- 例1:
err = f.SetSheetViewOptions("Sheet1", -1, ShowGridLines(false))
- 例2:
f := excelize.NewFile()
const sheet = "Sheet1"
if err := f.SetSheetViewOptions(sheet, 0,
excelize.DefaultGridColor(false),
excelize.ShowFormulas(true),
excelize.ShowGridLines(true),
excelize.ShowRowColHeaders(true),
excelize.RightToLeft(false),
excelize.ShowRuler(false),
excelize.View("pageLayout"),
excelize.TopLeftCell("C3"),
excelize.ZoomScale(80),
); err != nil {
fmt.Println(err)
}
var zoomScale ZoomScale
fmt.Println("Default:")
fmt.Println("- zoomScale: 80")
if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
fmt.Println(err)
}
if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
fmt.Println(err)
}
fmt.Println("Used out of range value:")
fmt.Println("- zoomScale:", zoomScale)
if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
fmt.Println(err)
}
if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
fmt.Println(err)
}
fmt.Println("Used correct value:")
fmt.Println("- zoomScale:", zoomScale)
得到输出:
Default:
- zoomScale: 80
Used out of range value:
- zoomScale: 80
Used correct value:
- zoomScale: 123