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

View File

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