Skip to content

Commit faa7285

Browse files
author
Harris
committed
Add support to flip outline summaries
This adds outlinePr support, with the summaryBelow attribute which defaults to true. Closes qax-os#304 Signed-off-by: Michael Harris
1 parent 4094e00 commit faa7285

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

sheetpr.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,26 @@ type (
3131
FitToPage bool
3232
// AutoPageBreaks is a SheetPrOption
3333
AutoPageBreaks bool
34+
// OutlineSummaryBelow is an outlinePr, within SheetPr option
35+
OutlineSummaryBelow bool
3436
)
3537

38+
func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) {
39+
if pr.OutlinePr == nil {
40+
pr.OutlinePr = new(xlsxOutlinePr)
41+
}
42+
pr.OutlinePr.SummaryBelow = bool(o)
43+
}
44+
45+
func (o *OutlineSummaryBelow) getSheetPrOption(pr *xlsxSheetPr) {
46+
// Excel default: true
47+
if pr == nil || pr.OutlinePr == nil {
48+
*o = true
49+
return
50+
}
51+
*o = OutlineSummaryBelow(defaultTrue(&pr.OutlinePr.SummaryBelow))
52+
}
53+
3654
func (o CodeName) setSheetPrOption(pr *xlsxSheetPr) {
3755
pr.CodeName = string(o)
3856
}
@@ -115,6 +133,7 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
115133
// Published(bool)
116134
// FitToPage(bool)
117135
// AutoPageBreaks(bool)
136+
// OutlineSummaryBelow(bool)
118137
func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error {
119138
sheet := f.workSheetReader(name)
120139
pr := sheet.SheetPr
@@ -137,6 +156,7 @@ func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error {
137156
// Published(bool)
138157
// FitToPage(bool)
139158
// AutoPageBreaks(bool)
159+
// OutlineSummaryBelow(bool)
140160
func (f *File) GetSheetPrOptions(name string, opts ...SheetPrOptionPtr) error {
141161
sheet := f.workSheetReader(name)
142162
pr := sheet.SheetPr

sheetpr_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var _ = []excelize.SheetPrOption{
1515
excelize.Published(false),
1616
excelize.FitToPage(true),
1717
excelize.AutoPageBreaks(true),
18+
excelize.OutlineSummaryBelow(true),
1819
}
1920

2021
var _ = []excelize.SheetPrOptionPtr{
@@ -23,6 +24,7 @@ var _ = []excelize.SheetPrOptionPtr{
2324
(*excelize.Published)(nil),
2425
(*excelize.FitToPage)(nil),
2526
(*excelize.AutoPageBreaks)(nil),
27+
(*excelize.OutlineSummaryBelow)(nil),
2628
}
2729

2830
func ExampleFile_SetSheetPrOptions() {
@@ -35,6 +37,7 @@ func ExampleFile_SetSheetPrOptions() {
3537
excelize.Published(false),
3638
excelize.FitToPage(true),
3739
excelize.AutoPageBreaks(true),
40+
excelize.OutlineSummaryBelow(false),
3841
); err != nil {
3942
panic(err)
4043
}
@@ -51,6 +54,7 @@ func ExampleFile_GetSheetPrOptions() {
5154
published excelize.Published
5255
fitToPage excelize.FitToPage
5356
autoPageBreaks excelize.AutoPageBreaks
57+
outlineSummaryBelow excelize.OutlineSummaryBelow
5458
)
5559

5660
if err := xl.GetSheetPrOptions(sheet,
@@ -59,6 +63,7 @@ func ExampleFile_GetSheetPrOptions() {
5963
&published,
6064
&fitToPage,
6165
&autoPageBreaks,
66+
&outlineSummaryBelow,
6267
); err != nil {
6368
panic(err)
6469
}
@@ -68,13 +73,15 @@ func ExampleFile_GetSheetPrOptions() {
6873
fmt.Println("- published:", published)
6974
fmt.Println("- fitToPage:", fitToPage)
7075
fmt.Println("- autoPageBreaks:", autoPageBreaks)
76+
fmt.Println("- outlineSummaryBelow:", outlineSummaryBelow)
7177
// Output:
7278
// Defaults:
7379
// - codeName: ""
7480
// - enableFormatConditionsCalculation: true
7581
// - published: true
7682
// - fitToPage: false
7783
// - autoPageBreaks: false
84+
// - outlineSummaryBelow: true
7885
}
7986

8087
func TestSheetPrOptions(t *testing.T) {
@@ -88,6 +95,7 @@ func TestSheetPrOptions(t *testing.T) {
8895
{new(excelize.Published), excelize.Published(false)},
8996
{new(excelize.FitToPage), excelize.FitToPage(true)},
9097
{new(excelize.AutoPageBreaks), excelize.AutoPageBreaks(true)},
98+
{new(excelize.OutlineSummaryBelow), excelize.OutlineSummaryBelow(false)},
9199
} {
92100
opt := test.nonDefault
93101
t.Logf("option %T", opt)

xmlWorksheet.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ type xlsxSheetPr struct {
211211
TransitionEntry bool `xml:"transitionEntry,attr,omitempty"`
212212
TabColor *xlsxTabColor `xml:"tabColor,omitempty"`
213213
PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
214+
OutlinePr *xlsxOutlinePr `xml:"outlinePr,omitempty"`
215+
}
216+
217+
// xlsxOutlinePr maps to the outlinePr element
218+
// SummaryBelow allows you to adjust the direction of grouper controls
219+
type xlsxOutlinePr struct {
220+
SummaryBelow bool `xml:"summaryBelow,attr"`
214221
}
215222

216223
// xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace

0 commit comments

Comments
 (0)