[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IPivotField.AutoSort

AutoSort Method

AutoSort(SortOrder?, string)

Establishes automatic field-sorting rules for a PivotTable field.

Use this method to apply automatic ascending or descending sorting to the current field in a PivotTable report.

Declaration
void AutoSort(SortOrder? order, string field = null)
Sub AutoSort(order As SortOrder?, Optional field As String = Nothing)
Parameters
Type Name Description
SortOrder? order

The sort order to apply. Must not be null.

string field

The source name of the data field used as the basis for automatic sorting. If this is null, the current field is used.

Examples
worksheet.Range["A1:C5"].Value = new object[,] {
    {"Product", "Region", "Amount"},
    {"Apple", "East", 120},
    {"Orange", "West", 80},
    {"Apple", "West", 150},
    {"Orange", "East", 90}
};
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:C5"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["E1"], "PivotTable1");
IPivotField fieldRegion = pivotTable.PivotFields["Region"];
fieldRegion.Orientation = PivotFieldOrientation.RowField;
fieldRegion.AutoSort(SortOrder.Descending);