Skip to main content
All docs
V24.1

How to: Apply a Color Filter in Spreadsheet Document API

  • 2 minutes to read

The following example describes how to filter data by fill settings, font color, and background color.

Turn on the filtering functionality for the required range, as described in the following example: How to: Enable Filtering.

Use the SheetAutoFilter.Columns property to obtain a collection of columns in the filtered range (AutoFilterColumnCollection). To filter data in a particular column, obtain the corresponding AutoFilterColumn object by its index in the collection.

Use one of the following methods to apply a color filter:

The following code sample shows how to filter data by color. The C column is filtered by fill parameters, and the D column - by font color.

spreadsheet filter by color

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

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

// Filter values in the "Products" column by fill settings.
AutoFilterColumn products = worksheet.AutoFilter.Columns[1];
products.ApplyFillFilter(worksheet["C10"].Fill);

// Filter values in the "Sales" column by font color.
AutoFilterColumn products = worksheet.AutoFilter.Columns[2];
products.ApplyFontColorFilter(worksheet["D10"].Font.Color);