Skip to main content
A newer version of this page is available. .

XlDynamicFilter Class

A dynamic filter that shows dates that fall within a specified time period or displays values that are above or below the average.

Namespace: DevExpress.Export.Xl

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

Declaration

public class XlDynamicFilter :
    IXlFilter,
    IXlFilterCriteria

Remarks

Create an instance of the XlDynamicFilter class and assign it to the XlFilterColumn.FilterCriteria or IXlTableColumn.FilterCriteria property to define the filter criteria for a worksheet or table column, respectively. Use the appropriate XlDynamicFilterType enumeration member to specify the dynamic filter type you wish to apply.

If you use a dynamic filter of the XlDynamicFilterType.AboveAverage or XlDynamicFilterType.BelowAverage type, you should assign the arithmetic mean of values in the filtered column to the XlDynamicFilter.Value property to perform filtering, since an exporter cannot calculate this value automatically.

Note

The dynamic filter criteria can change when the data to which the filter is applied or the current system date changes.

Refer to the Filtering article to learn more about filtering in the Excel Export Library.

Example

Note

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

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

// Create a dynamic filter to display dates that occur this month.
XlDynamicFilter filter = new XlDynamicFilter(XlDynamicFilterType.ThisMonth);
sheet.AutoFilterColumns.Add(new XlFilterColumn(0, filter));
// Start filtering data.
sheet.BeginFiltering(sheet.DataRange);

// Generate data for the document.
string[] customers = new string[] { "Tom's Club", "E-Mart", "K&S Music", "Walters" };
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 = DateTime.Now.AddDays(-7 * (7 - i));
            cell.ApplyFormatting(rowFormatting);
        }
        using (IXlCell cell = row.CreateCell())
        {
            cell.Value = customers[i % 4];
            cell.ApplyFormatting(rowFormatting);
        }
        using (IXlCell cell = row.CreateCell())
        {
            cell.Value = amount[i];
            cell.ApplyFormatting(rowFormatting);
        }
    }
}

// Finish filtering.
sheet.EndFiltering();

Implements

Inheritance

Object
XlDynamicFilter
See Also