Back to Devexpress

XlDateGroupItem Class

corelibraries-devexpress-dot-export-dot-xl-99275851.md

latest4.7 KB
Original Source

XlDateGroupItem Class

A group of dates or times used in the filter criteria.

Namespace : DevExpress.Export.Xl

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public class XlDateGroupItem
vb
Public Class XlDateGroupItem

Remarks

Use the XlDateGroupItem class instance to specify filter values for a date and time filter. When you create a new XlDateGroupItem object, you should specify the base date or time value to filter by (XlDateGroupItem.Value) and the part of this value to use in the filter criteria (XlDateGroupItem.GroupingType).

Add the created XlDateGroupItem instance to the DateGroups collection of the XlValuesFilter object to construct the filter criteria.

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/excel-export-api-examples

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

// Create a date filter to display sales data for the current year.
XlValuesFilter filter = new XlValuesFilter();
filter.DateGroups.Add(new XlDateGroupItem(DateTime.Today, XlDateTimeGroupingType.Year));
sheet.AutoFilterColumns.Add(new XlFilterColumn(0, filter));
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 = (i < 4) ? new DateTime(DateTime.Today.AddYears(-1).Year, 9 + i, 2 * i + 7) : new DateTime(DateTime.Today.Year, i - 3, 2 * i + 7);
            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();
vb
' Generate the header row.
Using row As IXlRow = sheet.CreateRow()
    row.BulkCells(New String() {"Date", "Customer", "Total"}, headerRowFormatting)
End Using

' Create a date filter to display sales data for the current year.
Dim filter As New XlValuesFilter()
filter.DateGroups.Add(New XlDateGroupItem(Date.Today, XlDateTimeGroupingType.Year))
sheet.AutoFilterColumns.Add(New XlFilterColumn(0, filter))
sheet.BeginFiltering(sheet.DataRange)

' Generate data for the document.
Dim customers() As String = {"Tom's Club", "E-Mart", "K&S Music", "Walters"}
Dim amount() As Integer = {6750, 4500, 3550, 4250, 5500, 6250, 5325, 4235}
For i As Integer = 0 To 7
    Using row As IXlRow = sheet.CreateRow()
        Using cell As IXlCell = row.CreateCell()
            cell.Value = If(i < 4, New Date(Date.Today.AddYears(-1).Year, 9 + i, 2 * i + 7), New Date(Date.Today.Year, i - 3, 2 * i + 7))
            cell.ApplyFormatting(rowFormatting)
        End Using
        Using cell As IXlCell = row.CreateCell()
            cell.Value = customers(i Mod 4)
            cell.ApplyFormatting(rowFormatting)
        End Using
        Using cell As IXlCell = row.CreateCell()
            cell.Value = amount(i)
            cell.ApplyFormatting(rowFormatting)
        End Using
    End Using
Next i

' Finish filtering.
sheet.EndFiltering()

Inheritance

Object XlDateGroupItem

See Also

XlDateGroupItem Members

Data Filtering in the Excel Export Library

DevExpress.Export.Xl Namespace