Class PivotDateTimeRangeGroupSettings
Contents
[
Hide
]PivotDateTimeRangeGroupSettings class
Represents the field grouped by date time range.
public class PivotDateTimeRangeGroupSettings : PivotFieldGroupSettings
Properties
| Name | Description |
|---|---|
| End { get; } | Gets the end date time of the group. |
| GroupByTypes { get; } | Gets the types of grouping by date time. |
| Interval { get; } | Gets the internal of the group. |
| Start { get; } | Gets the start date time of the group. |
| override Type { get; } | Gets the data time group type. |
Methods
| Name | Description |
|---|---|
| IsGroupedBy(PivotGroupByType) | Check whether the field is grouped by the type. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using Aspose.Cells.Pivot;
using System;
public class PivotClassPivotDateTimeRangeGroupSettingsDemo
{
public static void Run()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
try
{
// Add sample data with dates
worksheet.Cells["A1"].PutValue("Date");
worksheet.Cells["A2"].PutValue(new DateTime(2023, 1, 1));
worksheet.Cells["A3"].PutValue(new DateTime(2023, 2, 1));
worksheet.Cells["A4"].PutValue(new DateTime(2023, 3, 1));
worksheet.Cells["B1"].PutValue("Value");
worksheet.Cells["B2"].PutValue(10);
worksheet.Cells["B3"].PutValue(20);
worksheet.Cells["B4"].PutValue(30);
// Create pivot table
int pivotIndex = worksheet.PivotTables.Add("=A1:B4", "E3", "PivotTable1");
PivotTable pivotTable = worksheet.PivotTables[pivotIndex];
// Add fields to pivot table
pivotTable.AddFieldToArea(PivotFieldType.Row, 0);
pivotTable.AddFieldToArea(PivotFieldType.Data, 1);
// Group the date field by months
PivotField dateField = pivotTable.RowFields[0];
DateTime startDate = new DateTime(2023, 1, 1);
DateTime endDate = new DateTime(2023, 12, 31);
dateField.GroupBy(startDate, endDate, new PivotGroupByType[] { PivotGroupByType.Months }, 1, false);
// Get the group settings
PivotDateTimeRangeGroupSettings groupSettings = (PivotDateTimeRangeGroupSettings)dateField.GroupSettings;
// Display group settings properties
Console.WriteLine($"Group Type: {groupSettings.Type}");
Console.WriteLine($"Start Date: {groupSettings.Start}");
Console.WriteLine($"End Date: {groupSettings.End}");
Console.WriteLine($"Interval: {groupSettings.Interval}");
Console.WriteLine($"Group By Types: {string.Join(", ", groupSettings.GroupByTypes)}");
// Check if grouped by months
bool isGroupedByMonths = groupSettings.IsGroupedBy(PivotGroupByType.Months);
Console.WriteLine($"Is grouped by months: {isGroupedByMonths}");
// Save the workbook
workbook.Save("PivotDateTimeRangeGroupSettingsDemo.xlsx");
Console.WriteLine("PivotDateTimeRangeGroupSettings demo completed successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error in PivotDateTimeRangeGroupSettings demo: {ex.Message}");
}
}
}
}
See Also
- class PivotFieldGroupSettings
- namespace Aspose.Cells.Pivot
- assembly Aspose.Cells