Skip to main content

XlColorFilter.FilterByCellColor Property

Gets or sets whether to use the cell’s fill or font color in the filter criteria.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v23.2.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

public bool FilterByCellColor { get; set; }

Property Value

Type Description
Boolean

true, to filter by the fill color; otherwise, false.

The default is true.

Remarks

Use the XlColorFilter.Color property to define the color to filter by, and then use the FilterByCellColor property to specify whether the filter should use the cell color or font color as a criterion.

You can also filter a column by a pattern fill applied to its cells. To do this, you should additionally specify the XlColorFilter.PatternType and XlColorFilter.PatternColor properties of the pattern fill you wish to use as a filter criterion.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

// Generate the header row.
using (IXlRow row = sheet.CreateRow())
    row.BulkCells(new string[] { "Region", "Product", "Sales" }, headerRowFormatting);

// Start filtering data in the "Product" column by the specified fill color.
XlColorFilter filter = new XlColorFilter();
filter.Color = XlColor.FromArgb(0x00ffcc99);
filter.FilterByCellColor = true;
sheet.AutoFilterColumns.Add(new XlFilterColumn(1, filter));
sheet.BeginFiltering(sheet.DataRange);

// Generate data for the document.
string[] products = new string[] { "Camembert Pierrot", "Gorgonzola Telino", "Mascarpone Fabioli", "Mozzarella di Giovanni" };
int[] amount = new int[] { 6750, 4500, 3550, 4250, 5500, 6250, 5325, 4235 };
for (int i = 0; i < 8; i++)
{
    using (IXlRow row = sheet.CreateRow())
    {
        using (IXlCell cell = row.CreateCell())
        {
            cell.Value = (i < 4) ? "East" : "West";
            cell.ApplyFormatting(rowFormatting);
        }
        using (IXlCell cell = row.CreateCell())
        {
            cell.Value = products[i % 4];
            cell.ApplyFormatting(rowFormatting);
            if (i % 4 == 0)
                cell.ApplyFormatting(XlFill.SolidFill(XlColor.FromArgb(0xffcc99)));
        }
        using (IXlCell cell = row.CreateCell())
        {
            cell.Value = amount[i];
            cell.ApplyFormatting(rowFormatting);
        }
    }
}

// Finish filtering.
sheet.EndFiltering();
See Also