XlColorFilter.PatternColor Property
Gets or sets the pattern color used in the filter criteria.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v23.2.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
Property Value
Type | Description |
---|---|
XlColor | An XlColor object that specifies the foreground color of the pattern fill used as a filter criterion. |
Remarks
To filter a column by a pattern fill applied to its cells, specify the following properties of the pattern style you wish to use as a filter criterion:
- XlColorFilter.Color - specifies the cell’s background color.
- XlColorFilter.PatternType - specifies the type of the pattern fill;
- PatternColor - specifies the foreground color of the pattern fill.
In addition, you should set the XlColorFilter.FilterByCellColor property to true to specify that the column is filtered by a cell fill, not a font color.
The following example demonstrates how to use a color filter to display cells to which a pattern fill is applied.
// 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 pattern fill.
XlColorFilter filter = new XlColorFilter();
filter.Color = XlColor.FromArgb(0x00ffcc99);
filter.FilterByCellColor = true;
filter.PatternColor = XlColor.FromArgb(0x00ff0000);
filter.PatternType = XlPatternType.LightDown;
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.PatternFill(XlPatternType.LightDown, XlColor.FromArgb(0x00ffcc99), XlColor.FromArgb(0x00ff0000)));
}
using (IXlCell cell = row.CreateCell())
{
cell.Value = amount[i];
cell.ApplyFormatting(rowFormatting);
}
}
}
// Finish filtering.
sheet.EndFiltering();
The following image shows the result of the above-mentioned code’s execution (the workbook is opened in Microsoft® Excel®).