Skip to content

Commit 29366fd

Browse files
committed
Add new fields for pivot table options and pivot field options
- Add new fields FieldPrintTitles and ItemPrintTitles in the PivotTableOptions data type - Add new fields ShowAll and InsertBlankRow in the PivotTableField data type - Export 4 constants ExtURIDataField, ExtURIPivotField, ExtURIPivotFilter and ExtURIPivotHierarchy - Update unit tests - Update dependencies modules
1 parent 8f87131 commit 29366fd

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ require (
88
github.com/stretchr/testify v1.8.4
99
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d
1010
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7
11-
golang.org/x/crypto v0.25.0
11+
golang.org/x/crypto v0.26.0
1212
golang.org/x/image v0.18.0
13-
golang.org/x/net v0.27.0
14-
golang.org/x/text v0.16.0
13+
golang.org/x/net v0.28.0
14+
golang.org/x/text v0.17.0
1515
)
1616

1717
require (

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7
1515
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
1616
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
1717
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
18-
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
19-
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
18+
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
19+
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
2020
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
2121
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
22-
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
23-
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
24-
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
25-
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
22+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
23+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
24+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
25+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
2626
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2727
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2828
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

pivotTable.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type PivotTableOptions struct {
5858
ShowRowStripes bool
5959
ShowColStripes bool
6060
ShowLastColumn bool
61+
FieldPrintTitles bool
62+
ItemPrintTitles bool
6163
PivotTableStyleName string
6264
}
6365

@@ -90,6 +92,8 @@ type PivotTableField struct {
9092
Data string
9193
Name string
9294
Outline bool
95+
ShowAll bool
96+
InsertBlankRow bool
9397
Subtotal string
9498
DefaultSubtotal bool
9599
NumFmt int
@@ -349,6 +353,8 @@ func (f *File) addPivotTable(cacheID, pivotTableID int, opts *PivotTableOptions)
349353
CreatedVersion: pivotTableVersion,
350354
CompactData: &opts.CompactData,
351355
ShowError: &opts.ShowError,
356+
FieldPrintTitles: opts.FieldPrintTitles,
357+
ItemPrintTitles: opts.ItemPrintTitles,
352358
DataCaption: "Values",
353359
Location: &xlsxLocation{
354360
Ref: topLeftCell + ":" + bottomRightCell,
@@ -555,6 +561,8 @@ func (f *File) addPivotFields(pt *xlsxPivotTableDefinition, opts *PivotTableOpti
555561
DataField: inPivotTableField(opts.Data, name) != -1,
556562
Compact: &rowOptions.Compact,
557563
Outline: &rowOptions.Outline,
564+
ShowAll: rowOptions.ShowAll,
565+
InsertBlankRow: rowOptions.InsertBlankRow,
558566
DefaultSubtotal: &rowOptions.DefaultSubtotal,
559567
Items: &xlsxItems{
560568
Count: len(items),
@@ -591,6 +599,8 @@ func (f *File) addPivotFields(pt *xlsxPivotTableDefinition, opts *PivotTableOpti
591599
DataField: inPivotTableField(opts.Data, name) != -1,
592600
Compact: &columnOptions.Compact,
593601
Outline: &columnOptions.Outline,
602+
ShowAll: columnOptions.ShowAll,
603+
InsertBlankRow: columnOptions.InsertBlankRow,
594604
DefaultSubtotal: &columnOptions.DefaultSubtotal,
595605
Items: &xlsxItems{
596606
Count: len(items),
@@ -831,12 +841,14 @@ func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (Pivot
831841
return opts, err
832842
}
833843
opts = PivotTableOptions{
834-
pivotTableXML: pivotTableXML,
835-
pivotCacheXML: pivotCacheXML,
836-
pivotSheetName: sheet,
837-
DataRange: fmt.Sprintf("%s!%s", pc.CacheSource.WorksheetSource.Sheet, pc.CacheSource.WorksheetSource.Ref),
838-
PivotTableRange: fmt.Sprintf("%s!%s", sheet, pt.Location.Ref),
839-
Name: pt.Name,
844+
pivotTableXML: pivotTableXML,
845+
pivotCacheXML: pivotCacheXML,
846+
pivotSheetName: sheet,
847+
DataRange: fmt.Sprintf("%s!%s", pc.CacheSource.WorksheetSource.Sheet, pc.CacheSource.WorksheetSource.Ref),
848+
PivotTableRange: fmt.Sprintf("%s!%s", sheet, pt.Location.Ref),
849+
Name: pt.Name,
850+
FieldPrintTitles: pt.FieldPrintTitles,
851+
ItemPrintTitles: pt.ItemPrintTitles,
840852
}
841853
if pc.CacheSource.WorksheetSource.Name != "" {
842854
opts.DataRange = pc.CacheSource.WorksheetSource.Name
@@ -924,7 +936,9 @@ func (f *File) extractPivotTableFields(order []string, pt *xlsxPivotTableDefinit
924936
// settings by given pivot table fields.
925937
func extractPivotTableField(data string, fld *xlsxPivotField) PivotTableField {
926938
pivotTableField := PivotTableField{
927-
Data: data,
939+
Data: data,
940+
ShowAll: fld.ShowAll,
941+
InsertBlankRow: fld.InsertBlankRow,
928942
}
929943
fields := []string{"Compact", "Name", "Outline", "Subtotal", "DefaultSubtotal"}
930944
immutable, mutable := reflect.ValueOf(*fld), reflect.ValueOf(&pivotTableField).Elem()

pivotTable_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func TestPivotTable(t *testing.T) {
3131
DataRange: "Sheet1!A1:E31",
3232
PivotTableRange: "Sheet1!G2:M34",
3333
Name: "PivotTable1",
34-
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
34+
Rows: []PivotTableField{{Data: "Month", ShowAll: true, DefaultSubtotal: true}, {Data: "Year"}},
3535
Filter: []PivotTableField{{Data: "Region"}},
36-
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
36+
Columns: []PivotTableField{{Data: "Type", ShowAll: true, InsertBlankRow: true, DefaultSubtotal: true}},
3737
Data: []PivotTableField{{Data: "Sales", Subtotal: "Sum", Name: "Summarize by Sum", NumFmt: 38}},
3838
RowGrandTotals: true,
3939
ColGrandTotals: true,
@@ -42,6 +42,8 @@ func TestPivotTable(t *testing.T) {
4242
ShowColHeaders: true,
4343
ShowLastColumn: true,
4444
ShowError: true,
45+
ItemPrintTitles: true,
46+
FieldPrintTitles: true,
4547
PivotTableStyleName: "PivotStyleLight16",
4648
}
4749
assert.NoError(t, f.AddPivotTable(expected))

templates.go

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const (
102102
ExtURICalcFeatures = "{B58B0392-4F1F-4190-BB64-5DF3571DCE5F}"
103103
ExtURIConditionalFormattingRuleID = "{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"
104104
ExtURIConditionalFormattings = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}"
105+
ExtURIDataField = "{E15A36E0-9728-4E99-A89B-3F7291B0FE68}"
105106
ExtURIDataModel = "{FCE2AD5D-F65C-4FA6-A056-5C36A1767C68}"
106107
ExtURIDataValidations = "{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"
107108
ExtURIDrawingBlip = "{28A0092B-C50C-407E-A947-70E740481C1C}"
@@ -112,6 +113,9 @@ const (
112113
ExtURIPivotCacheDefinition = "{725AE2AE-9491-48be-B2B4-4EB974FC3084}"
113114
ExtURIPivotCachesX14 = "{876F7934-8845-4945-9796-88D515C7AA90}"
114115
ExtURIPivotCachesX15 = "{841E416B-1EF1-43b6-AB56-02D37102CBD5}"
116+
ExtURIPivotField = "{2946ED86-A175-432a-8AC1-64E0C546D7DE}"
117+
ExtURIPivotFilter = "{0605FD5F-26C8-4aeb-8148-2DB25E43C511}"
118+
ExtURIPivotHierarchy = "{F1805F06-0CD304483-9156-8803C3D141DF}"
115119
ExtURIPivotTableReferences = "{983426D0-5260-488c-9760-48F4B6AC55F4}"
116120
ExtURIProtectedRanges = "{FC87AEE6-9EDD-4A0A-B7FB-166176984837}"
117121
ExtURISlicerCacheDefinition = "{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}"

0 commit comments

Comments
 (0)