Expanding and collapsing Pivot Table items - DON-PHAM/EPPlus GitHub Wiki

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;