Skip to content

Add new functions DeleteSlicer and GetSlicers #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7191e7c
Add drawing graphic structs
zhangyimingdatiancai Jul 4, 2024
904f070
Update structs for parsing slicer shapes
zhangyimingdatiancai Jul 8, 2024
78fbfc2
Support get tables and fix code review issue
zhangyimingdatiancai Jul 15, 2024
6d1125e
Add new function GetSlicers
zhangyimingdatiancai Aug 6, 2024
586f308
Optimize ColumnNumberToName function performance, reduce about 50% me…
zhayt Jul 5, 2024
3cfdf0a
This closes #1937, fix GetPivotTables returns incorrect data range (#…
ShowerBandV Jul 6, 2024
3e84ca6
This closes #1940, SetCellHyperLink function now support remove hyper…
xuri Jul 7, 2024
33593a0
This closes #1944, add new TickLabelPosition field in the ChartAxis d…
imink Jul 11, 2024
82047f0
This closes #1942, fix percent sign missing in formatted result for z…
samkeke Jul 12, 2024
13b714a
This closes #1945, an error will be return if column header cell is e…
xuri Jul 13, 2024
99cce9d
This fix missing horizontal axis in scatter chart with negative value…
pjh591029530 Jul 17, 2024
12694aa
This closes #1955, refs #119, support to set cell value with an IEEE …
xuri Jul 18, 2024
43b1d05
This closes #1957, fix missing shape macro missing after adjusted dra…
xuri Jul 19, 2024
8f6719b
This close #1963, prevent the GetStyle function panic when theme with…
xuri Jul 23, 2024
a415598
This closes #1968, closes #1969
xuri Jul 31, 2024
6df4a37
This closes #1957, fix missing shape macro missing after adjusted dra…
xuri Jul 19, 2024
755ff98
Merge branch 'qax-os:master' into slicers
zhangyimingdatiancai Aug 6, 2024
92609c8
Unit tests for the GetSlicers function
zhangyimingdatiancai Aug 9, 2024
98afbbf
Merge branch 'qax-os:master' into slicers
zhangyimingdatiancai Aug 18, 2024
a380981
Add new support for delete slicers by the DeleteSlicer function
zhangyimingdatiancai Aug 18, 2024
678c205
Lint code with gofmt
zhangyimingdatiancai Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func newInvalidStyleID(styleID int) error {
return fmt.Errorf("invalid style ID %d", styleID)
}

// newNoExistSlicerError defined the error message on receiving the non existing
// slicer name.
func newNoExistSlicerError(name string) error {
return fmt.Errorf("slicer %s does not exist", name)
}

// newNoExistTableError defined the error message on receiving the non existing
// table name.
func newNoExistTableError(name string) error {
Expand Down
29 changes: 21 additions & 8 deletions pivotTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,11 @@ func (f *File) getPivotTableDataRange(opts *PivotTableOptions) error {
opts.pivotDataRange = opts.DataRange
return nil
}
for _, sheetName := range f.GetSheetList() {
tables, err := f.GetTables(sheetName)
e := ErrSheetNotExist{sheetName}
if err != nil && err.Error() != newNotWorksheetError(sheetName).Error() && err.Error() != e.Error() {
return err
}
tbls, err := f.getTables()
if err != nil {
return err
}
for sheetName, tables := range tbls {
for _, table := range tables {
if table.Name == opts.DataRange {
opts.pivotDataRange, opts.namedDataRange = fmt.Sprintf("%s!%s", sheetName, table.Range), true
Expand Down Expand Up @@ -1016,8 +1015,8 @@ func (f *File) DeletePivotTable(sheet, name string) error {
return err
}
pivotTableCaches := map[string]int{}
for _, sheetName := range f.GetSheetList() {
sheetPivotTables, _ := f.GetPivotTables(sheetName)
pivotTables, _ := f.getPivotTables()
for _, sheetPivotTables := range pivotTables {
for _, sheetPivotTable := range sheetPivotTables {
pivotTableCaches[sheetPivotTable.pivotCacheXML]++
}
Expand All @@ -1038,3 +1037,17 @@ func (f *File) DeletePivotTable(sheet, name string) error {
}
return newNoExistTableError(name)
}

// getPivotTables provides a function to get all pivot tables in a workbook.
func (f *File) getPivotTables() (map[string][]PivotTableOptions, error) {
pivotTables := map[string][]PivotTableOptions{}
for _, sheetName := range f.GetSheetList() {
pts, err := f.GetPivotTables(sheetName)
e := ErrSheetNotExist{sheetName}
if err != nil && err.Error() != newNotWorksheetError(sheetName).Error() && err.Error() != e.Error() {
return pivotTables, err
}
pivotTables[sheetName] = append(pivotTables[sheetName], pts...)
}
return pivotTables, nil
}
2 changes: 2 additions & 0 deletions pivotTable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ func TestPivotTable(t *testing.T) {
f.Pkg.Store("xl/pivotTables/pivotTable1.xml", MacintoshCyrillicCharset)
_, err = f.GetPivotTables("Sheet1")
assert.EqualError(t, err, "XML syntax error on line 1: invalid UTF-8")
_, err = f.getPivotTables()
assert.EqualError(t, err, "XML syntax error on line 1: invalid UTF-8")
assert.NoError(t, f.Close())
}

Expand Down
Loading