From 90221bd98fab0ce85a177d955d79a964bb4b66b2 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 18 Dec 2018 21:50:07 +0800 Subject: [PATCH] Fixes #310, support set and get TopLeftCell properties of sheet view options --- sheetview.go | 10 ++++++++++ sheetview_test.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sheetview.go b/sheetview.go index e76325c..37a0c39 100644 --- a/sheetview.go +++ b/sheetview.go @@ -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)) } diff --git a/sheetview_test.go b/sheetview_test.go index c580906..ee81d5b 100644 --- a/sheetview_test.go +++ b/sheetview_test.go @@ -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) {