From 7999a492a4b7a302ecf31c990d1e1e9ff3146d74 Mon Sep 17 00:00:00 2001 From: ShowerBandV <59394693+ShowerBandV@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:25:09 +0800 Subject: [PATCH] This closes #1937, fix GetPivotTables returns incorrect data range (#1941) - Add unit test for get pivot table with across worksheet data range, update dependencies package and updated comments of the GetMergeCells function --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- merge.go | 4 ++-- pivotTable.go | 2 +- pivotTable_test.go | 7 +++++++ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index ee3d8e5..6e31bbc 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 - golang.org/x/crypto v0.23.0 - golang.org/x/image v0.14.0 - golang.org/x/net v0.25.0 - golang.org/x/text v0.15.0 + golang.org/x/crypto v0.25.0 + golang.org/x/image v0.18.0 + golang.org/x/net v0.27.0 + golang.org/x/text v0.16.0 ) require ( diff --git a/go.sum b/go.sum index cb62504..904edc8 100644 --- a/go.sum +++ b/go.sum @@ -15,14 +15,14 @@ github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7 github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A= github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= -golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/merge.go b/merge.go index 2574c6c..63427ba 100644 --- a/merge.go +++ b/merge.go @@ -139,8 +139,8 @@ func (f *File) UnmergeCell(sheet, topLeftCell, bottomRightCell string) error { return nil } -// GetMergeCells provides a function to get all merged cells from a worksheet -// currently. +// GetMergeCells provides a function to get all merged cells from a specific +// worksheet. func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) { var mergeCells []MergeCell ws, err := f.workSheetReader(sheet) diff --git a/pivotTable.go b/pivotTable.go index 0b6ad3b..c3b9ea6 100644 --- a/pivotTable.go +++ b/pivotTable.go @@ -806,7 +806,7 @@ func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (Pivot pivotTableXML: pivotTableXML, pivotCacheXML: pivotCacheXML, pivotSheetName: sheet, - DataRange: fmt.Sprintf("%s!%s", sheet, pc.CacheSource.WorksheetSource.Ref), + DataRange: fmt.Sprintf("%s!%s", pc.CacheSource.WorksheetSource.Sheet, pc.CacheSource.WorksheetSource.Ref), PivotTableRange: fmt.Sprintf("%s!%s", sheet, pt.Location.Ref), Name: pt.Name, } diff --git a/pivotTable_test.go b/pivotTable_test.go index 49bc7d9..f3bb2bf 100644 --- a/pivotTable_test.go +++ b/pivotTable_test.go @@ -139,6 +139,13 @@ func TestPivotTable(t *testing.T) { ShowColHeaders: true, ShowLastColumn: true, })) + + // Test get pivot table with across worksheet data range + pivotTables, err = f.GetPivotTables("Sheet2") + assert.NoError(t, err) + assert.Len(t, pivotTables, 1) + assert.Equal(t, "Sheet1!A1:E31", pivotTables[0].DataRange) + assert.NoError(t, f.AddPivotTable(&PivotTableOptions{ DataRange: "Sheet1!A1:E31", PivotTableRange: "Sheet2!A20:AR60",