-
Notifications
You must be signed in to change notification settings - Fork 287
Pivot table sorting
Mats Alm edited this page Nov 6, 2023
·
6 revisions
You can sort pivot tables by setting the PivotTable Field - Sort
property.
rf.Sort = eSortType.Ascending;
This applies to column and row fields.
You can also sort on data fields by using the SetAutoSort
method.
rowField.SetAutoSort(df, eSortType.Descending);
This method sets the AutoSort
property that contains the pivot area to set for the pivot table field sorting.
If you have multiple row and column fields you can set the auto sort by using pivot areas. This sample sorts by the column field value "Hardware".
var rowField = p1.RowFields.Add(p1.Fields[0]);
var columnField = p1.ColumnFields.Add(p1.Fields[1]);
var dataField = p1.DataFields.Add(p1.Fields[3]);
rf.SetAutoSort(df, eSortType.Descending);
var reference = rf.AutoSort.Conditions.Fields.Add(cf);
cf.Items.Refresh(); //You must refresh the items to fill the items collection with the correct values.
reference.Items.AddByValue("Hardware");
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles