From a292d833e0e62f37a6a587ecf83075ad4b9a44e6 Mon Sep 17 00:00:00 2001 From: JanKallman Date: Fri, 15 Nov 2024 14:38:33 +0100 Subject: [PATCH] Fixed small issue with slicer fields on pivot tables --- .../Slicer/ExcelPivotTableSlicerCache.cs | 2 +- .../PivotTable/ExcelPivotTableCacheField.cs | 21 ++++++++++++------- .../ExcelPivotTableFieldCollectionBase.cs | 1 - 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/EPPlus/Drawing/Slicer/ExcelPivotTableSlicerCache.cs b/src/EPPlus/Drawing/Slicer/ExcelPivotTableSlicerCache.cs index da2fa166d..9e58ce5c5 100644 --- a/src/EPPlus/Drawing/Slicer/ExcelPivotTableSlicerCache.cs +++ b/src/EPPlus/Drawing/Slicer/ExcelPivotTableSlicerCache.cs @@ -49,7 +49,7 @@ internal void Init(ExcelWorkbook wb, string name, ExcelPivotTableField field) PivotTables.Add(_field.PivotTable); CreateWorkbookReference(wb, ExtLstUris.WorkbookSlicerPivotTableUri); SlicerCacheXml.Save(Part.GetStream()); - Data.Items.Refresh(); + Data.Items.Refresh(); } /// /// Init must be called before accessing any properties as it sets several properties. diff --git a/src/EPPlus/Table/PivotTable/ExcelPivotTableCacheField.cs b/src/EPPlus/Table/PivotTable/ExcelPivotTableCacheField.cs index 431cf2eeb..aede3f753 100644 --- a/src/EPPlus/Table/PivotTable/ExcelPivotTableCacheField.cs +++ b/src/EPPlus/Table/PivotTable/ExcelPivotTableCacheField.cs @@ -885,16 +885,18 @@ internal void Refresh() private void UpdateGroupItems() { foreach (var pt in _cache._pivotTables) - { - if ((pt.Fields[Index].IsRowField || - pt.Fields[Index].IsColumnField || - pt.Fields[Index].IsPageField || pt.Fields[Index].Cache.HasSlicer) ) + { + var fld = pt.Fields[Index]; + if ((fld.IsRowField || + fld.IsColumnField || + fld.IsPageField || fld.Cache.HasSlicer) ) { - pt.Fields[Index].UpdateGroupItems(this, true); + fld.UpdateGroupItems(this, true); + fld.Items.MatchValueToIndex(); } else { - pt.Fields[Index].DeleteNode("d:items"); + fld.DeleteNode("d:items"); } } } @@ -941,7 +943,12 @@ private void UpdateSharedItems() { UpdateSlicers(); } - } + //Match items in pivot tables. + foreach (var pt in _cache._pivotTables) + { + pt.Fields[Index].Items.MatchValueToIndex(); + } + } private void UpdatePivotItemsFromSharedItems(HashSet siHs) { diff --git a/src/EPPlus/Table/PivotTable/ExcelPivotTableFieldCollectionBase.cs b/src/EPPlus/Table/PivotTable/ExcelPivotTableFieldCollectionBase.cs index fa90192a7..9fda19297 100644 --- a/src/EPPlus/Table/PivotTable/ExcelPivotTableFieldCollectionBase.cs +++ b/src/EPPlus/Table/PivotTable/ExcelPivotTableFieldCollectionBase.cs @@ -189,7 +189,6 @@ public void SelectSingleItem(int index) public void Refresh() { _field.Cache.Refresh(); - MatchValueToIndex(); _hiddenItemIndex = null; }