Back to Devexpress

XlsxExportOptionsEx.DocumentColumnFiltering Event

corelibraries-devexpress-dot-xtraprinting-dot-xlsxexportoptionsex-70856115.md

latest4.2 KB
Original Source

XlsxExportOptionsEx.DocumentColumnFiltering Event

Allows you to apply filters to the exported document’s columns.Only available in data-aware export mode.

Namespace : DevExpress.XtraPrinting

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public event DocumentColumnFilteringEventHandler DocumentColumnFiltering
vb
Public Event DocumentColumnFiltering As DocumentColumnFilteringEventHandler

Remarks

The DocumentColumnFiltering event fires repeatedly for each exported column, allowing you to specify a filter for this column. To specify a filter for a column, create one of the following objects and assign it to the event’s Filter parameter:

  • XlDynamicFilter - A smart filter whose results may depend on the data to which it is applied or the current date (AboveAverage, LastMonth, LastYear, NextMonth, ThisQuarter, ThisWeek, Today, etc.).
  • XlCustomFilters - A filter that consists of one or two expressions.
  • XlTop10Filter - A filter that selects the top N or bottom N items.
  • XlValuesFilter - A filter that selects items with certain values.
  • XlColorFilter - A filter that selects items with a certain fill or font color.

Example

The XlsxExportOptionsEx.DocumentColumnFiltering event allows you to apply filter criteria to columns in the exported XLSX document. This example shows how to apply filters to two columns when exporting data from a Data Grid’s GridView.

csharp
using DevExpress.Export.Xl;
using DevExpress.XtraPrinting;
using System.Diagnostics;

private void btnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    string path = "grid-export.xlsx";
    XlsxExportOptionsEx op = new XlsxExportOptionsEx();
    op.DocumentColumnFiltering += Op_DocumentColumnFiltering;
    gridView1.ExportToXlsx(path, op);
    Process.Start(path);
}

private void Op_DocumentColumnFiltering(DevExpress.Export.DocumentColumnFilteringEventArgs e) {
    if (e.ColumnFieldName == "OrderDate") {
        e.Filter = new XlDynamicFilter(XlDynamicFilterType.LastMonth);
    }
    if (e.ColumnFieldName == "Quantity") {
        e.Filter = new XlCustomFilters(new XlCustomFilterCriteria(XlFilterOperator.GreaterThanOrEqual, 10));
    }
}
vb
Imports DevExpress.Export.Xl
Imports DevExpress.XtraPrinting

Private Sub btnExport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnExport.ItemClick
    Dim path As String = "grid-export.xlsx"
    Dim op As New XlsxExportOptionsEx()
    AddHandler op.DocumentColumnFiltering, AddressOf Op_DocumentColumnFiltering
    GridView1.ExportToXlsx(path, op)
    Process.Start(path)
End Sub

Private Sub Op_DocumentColumnFiltering(e As DevExpress.Export.DocumentColumnFilteringEventArgs)
    If e.ColumnFieldName = "OrderDate" Then
        e.Filter = New XlDynamicFilter(XlDynamicFilterType.LastMonth)
    End If
    If e.ColumnFieldName = "Quantity" Then
        e.Filter = New XlCustomFilters(New XlCustomFilterCriteria(XlFilterOperator.GreaterThanOrEqual, 10))
    End If
End Sub

See Also

OptionsColumn.Printable

TreeListOptionsColumn.Printable

XlsxExportOptionsEx Class

XlsxExportOptionsEx Members

DevExpress.XtraPrinting Namespace