Skip to content

Expanding and collapsing Pivot Table items

Mats Alm edited this page Nov 6, 2023 · 3 revisions

After generating a pivot table, you sometimes want to collapse or expand all or individual items in a row- or column field. You can do this with EPPlus using the ExcelPivotTableFieldItemsCollection.ShowDetails method or the ExcelPivotTableFieldItem.ShowDetails Property. First however you must refresh the pivot table cache, so the cache items are generated. Here is an example of how to collapse all items for a column field.

//First you need to refresh the items, the you can set the ShowDetails flag for all items or on an individual item.
pivotTable.ColumnFields[0].Items.Refresh();
pivotTable.ColumnFields[0].Items.ShowDetails(false);

You can also collapse or expand individual items after the items cache has been refreshed.

pivotTable.ColumnFields[0].Items[0].ShowDetails = false;

See also

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally