Fixes #310, support set and get TopLeftCell properties of sheet view options

This commit is contained in:
xuri 2018-12-18 21:50:07 +08:00
parent d166d2e06f
commit 90221bd98f
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 28 additions and 0 deletions

View File

@ -35,6 +35,8 @@ type (
ShowRowColHeaders bool
// ZoomScale is a SheetViewOption.
ZoomScale float64
// TopLeftCell is a SheetViewOption.
TopLeftCell string
/* TODO
// ShowWhiteSpace is a SheetViewOption.
ShowWhiteSpace bool
@ -47,6 +49,14 @@ type (
// Defaults for each option are described in XML schema for CT_SheetView
func (o TopLeftCell) setSheetViewOption(view *xlsxSheetView) {
view.TopLeftCell = string(o)
}
func (o *TopLeftCell) getSheetViewOption(view *xlsxSheetView) {
*o = TopLeftCell(string(view.TopLeftCell))
}
func (o DefaultGridColor) setSheetViewOption(view *xlsxSheetView) {
view.DefaultGridColor = boolPtr(bool(o))
}

View File

@ -13,12 +13,14 @@ var _ = []excelize.SheetViewOption{
excelize.ShowFormulas(false),
excelize.ShowGridLines(true),
excelize.ShowRowColHeaders(true),
excelize.TopLeftCell("B2"),
// SheetViewOptionPtr are also SheetViewOption
new(excelize.DefaultGridColor),
new(excelize.RightToLeft),
new(excelize.ShowFormulas),
new(excelize.ShowGridLines),
new(excelize.ShowRowColHeaders),
new(excelize.TopLeftCell),
}
var _ = []excelize.SheetViewOptionPtr{
@ -27,6 +29,7 @@ var _ = []excelize.SheetViewOptionPtr{
(*excelize.ShowFormulas)(nil),
(*excelize.ShowGridLines)(nil),
(*excelize.ShowRowColHeaders)(nil),
(*excelize.TopLeftCell)(nil),
}
func ExampleFile_SetSheetViewOptions() {
@ -40,6 +43,7 @@ func ExampleFile_SetSheetViewOptions() {
excelize.ShowGridLines(true),
excelize.ShowRowColHeaders(true),
excelize.ZoomScale(80),
excelize.TopLeftCell("C3"),
); err != nil {
panic(err)
}
@ -91,6 +95,7 @@ func ExampleFile_GetSheetViewOptions() {
showGridLines excelize.ShowGridLines
showRowColHeaders excelize.ShowRowColHeaders
zoomScale excelize.ZoomScale
topLeftCell excelize.TopLeftCell
)
if err := xl.GetSheetViewOptions(sheet, 0,
@ -100,6 +105,7 @@ func ExampleFile_GetSheetViewOptions() {
&showGridLines,
&showRowColHeaders,
&zoomScale,
&topLeftCell,
); err != nil {
panic(err)
}
@ -111,6 +117,15 @@ func ExampleFile_GetSheetViewOptions() {
fmt.Println("- showGridLines:", showGridLines)
fmt.Println("- showRowColHeaders:", showRowColHeaders)
fmt.Println("- zoomScale:", zoomScale)
fmt.Println("- topLeftCell:", `"`+topLeftCell+`"`)
if err := xl.SetSheetViewOptions(sheet, 0, excelize.TopLeftCell("B2")); err != nil {
panic(err)
}
if err := xl.GetSheetViewOptions(sheet, 0, &topLeftCell); err != nil {
panic(err)
}
if err := xl.SetSheetViewOptions(sheet, 0, excelize.ShowGridLines(false)); err != nil {
panic(err)
@ -122,6 +137,7 @@ func ExampleFile_GetSheetViewOptions() {
fmt.Println("After change:")
fmt.Println("- showGridLines:", showGridLines)
fmt.Println("- topLeftCell:", topLeftCell)
// Output:
// Default:
@ -131,8 +147,10 @@ func ExampleFile_GetSheetViewOptions() {
// - showGridLines: true
// - showRowColHeaders: true
// - zoomScale: 0
// - topLeftCell: ""
// After change:
// - showGridLines: false
// - topLeftCell: B2
}
func TestSheetViewOptionsErrors(t *testing.T) {