Back to Devexpress

How to: Apply a Custom Text Filter

officefileapi-113762-spreadsheet-document-api-examples-filter-data-how-to-apply-a-custom-text-filter.md

latest2.6 KB
Original Source

How to: Apply a Custom Text Filter

  • Sep 19, 2023
  • 2 minutes to read

This example demonstrates how to specify the custom compound filter criteria to filter text values in a column.

  1. Turn on the filtering functionality for the required range, as described in the How to: Enable Filtering example.
  2. Use the AutoFilterBase.Columns property of the SheetAutoFilter object to get a collection of columns in the filtered range (the AutoFilterColumnCollection object). Each column in the collection is defined by the AutoFilterColumn object, which provides basic methods for data filtering. To filter data in a particular column, get access to this column by its index in the AutoFilterColumnCollection collection.
  3. To apply a custom complex filter, call the AutoFilterColumn.ApplyCustomFilter method overload with five parameters.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Regional sales"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);

// Filter values in the "Product" column that contain "Gi" and include empty cells.
AutoFilterColumn products = worksheet.AutoFilter.Columns[1];
products.ApplyCustomFilter("*Gi*", FilterComparisonOperator.Equal, FilterValue.FilterByBlank, FilterComparisonOperator.Equal, false);
vb
Dim worksheet As Worksheet = workbook.Worksheets("Regional sales")
workbook.Worksheets.ActiveWorksheet = worksheet

' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)

' Filter values in the "Product" column that contain "Gi" and include empty cells.
Dim products As AutoFilterColumn = worksheet.AutoFilter.Columns(1)
products.ApplyCustomFilter("*Gi*", FilterComparisonOperator.Equal, FilterValue.FilterByBlank, FilterComparisonOperator.Equal, False)