Click or drag to resize

CustomFilter Class

Represents a filter that specifies one or two conditions (operators and values) and whether the two conditions are joined by 'and' or 'or'.
Inheritance Hierarchy

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 41.3.30.1132
Syntax
public sealed class CustomFilter : Filter

The CustomFilter type exposes the following members.

Properties
  NameDescription
Public propertyAnd
Gets or sets the value indicating whether the two conditions have an "and" relationship. indicates "and", indicates "or" and indicates that second condition won't be applied.
Public propertyFilterType
Gets the Custom value.
(Overrides FilterFilterType.)
Public propertyOperator
Gets or sets the operator used by the (first) filter condition.
Public propertyOperator2
Gets or sets the operator used by the second filter condition.
Public propertyValue

Gets or sets the value used by the (first) filter condition.

The value's type must be supported in Value ( and types supported in SupportsType(Type)).

Public propertyValue2

Gets or sets the value used by the second filter condition.

The value's type must be supported in Value ( and types supported in SupportsType(Type)).

Top
Methods
Examples

Following methods shows various ways to specify and apply an AutoFilter to a range of cells.

static void Filter1(ExcelWorksheet worksheet)
{
    // Specify and apply Filter using less-verbose, fluent, but less understandable interface.
    worksheet.Cells.GetSubrange("A1", "D20").Filter().
        ByValues(0, null, "$5,400.00", "John Doe", new DateTimeGroup(2015, 5)).
        ByTop10(1, true, true, 20).
        ByCustom(2, FilterOperator.GreaterThanOrEqual, 2000, true, FilterOperator.LessThanOrEqual, 8000).
        ByDynamic(3, DynamicFilterType.AboveAverage).
        Apply();
}

static void Filter2(ExcelWorksheet worksheet)
{
    // Specify and apply Filter using more verbose, but more understandable interface.
    var filter = worksheet.Cells.GetSubrange("A1", "D20").Filter();

    var valuesFilter = filter.Columns[0].SetValuesFilter();
    valuesFilter.SetValues(null, "$5,400.00", "John Doe", new DateTimeGroup(2015, 5));

    var top10Filter = filter.Columns[1].SetTop10Filter();
    top10Filter.Top = true;
    top10Filter.Percent = true;
    top10Filter.Value = 20;

    var customFilter = filter.Columns[2].SetCustomFilter();
    customFilter.Operator = FilterOperator.GreaterThanOrEqual;
    customFilter.Value = 2000;
    customFilter.And = true;
    customFilter.Operator2 = FilterOperator.LessThanOrEqual;
    customFilter.Value2 = 8000;

    var dynamicFilter = filter.Columns[3].SetDynamicFilter();
    dynamicFilter.DynamicFilterType = DynamicFilterType.AboveAverage;

    filter.Apply();
}

static void Filter3(ExcelWorksheet worksheet)
{
    // Specify and apply Filter using less-verbose, fluent and understandable interface (with help of C# 4.0 named arguments).
    worksheet.Cells.GetSubrange("A1", "D20").Filter().
        ByValues(columnIndex: 0, values: new object[] { null, "$5,400.00", "John Doe", new DateTimeGroup(2015, 5) }).
        ByTop10(columnIndex: 1, top: true, percent: true, value: 20).
        ByCustom(columnIndex: 2, @operator: FilterOperator.GreaterThanOrEqual, value: 2000, and: true, operator2: FilterOperator.LessThanOrEqual, value2: 8000).
        ByDynamic(columnIndex: 3, dynamicFilterType: DynamicFilterType.AboveAverage).
        Apply();
}
See Also