[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IPivotFilters.Add

Add Method

Add(PivotFilterType, object, object, PivotFilterOptions)

Adds a new filter to the pivot filter collection.

Use this method to create a pivot filter that requires two criterion values, such as a between or not-between condition. This overload calls Add(PivotFilterType, object, object, PivotFilterOptions) with null for the options argument.

Declaration
IPivotFilter Add(PivotFilterType type, object value1 = null, object value2 = null, PivotFilterOptions options = null)
Function Add(type As PivotFilterType, Optional value1 As Object = Nothing, Optional value2 As Object = Nothing, Optional options As PivotFilterOptions = Nothing) As IPivotFilter
Parameters
Type Name Description
PivotFilterType type

The type of filter to add.

object value1

The first filter value. Its meaning depends on type; null is allowed when the specified filter type does not require a first value.

object value2

The second filter value. Its meaning depends on type; null is allowed when the specified filter type does not require a second value.

PivotFilterOptions options

Optional settings for the filter.

Returns
Type Description
IPivotFilter

The added pivot filter.

Examples
object[,] sourceData = new object[,] {
    {"Product", "Category", "Amount"},
    {"Example Speaker", "Consumer Electronics", 4270},
    {"Example Camera", "Consumer Electronics", 8239},
    {"Example TV", "Consumer Electronics", 2626},
    {"Example Smartphone", "Mobile", 8250}
};
worksheet.Range["A1:C5"].Value = sourceData;
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:C5"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["E1"], "PivotTable1");
IPivotField productField = pivotTable.PivotFields["Product"];
productField.Orientation = PivotFieldOrientation.RowField;
IPivotField amountField = pivotTable.PivotFields["Amount"];
amountField.Orientation = PivotFieldOrientation.DataField;
PivotFilterOptions options = new PivotFilterOptions();
options.AppliedDataField = 0;
IPivotFilter filter = productField.PivotFilters.Add(PivotFilterType.ValueGreaterThan, 7000, null, options);
IPivotField dataField = filter.DataField;