[]
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.
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
| Type | Name | Description |
|---|---|---|
| PivotFilterType | type | The type of filter to add. |
| object | value1 | The first filter value. Its meaning depends on |
| object | value2 | The second filter value. Its meaning depends on |
| PivotFilterOptions | options | Optional settings for the filter. |
| Type | Description |
|---|---|
| IPivotFilter | The added pivot filter. |
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;