Class PivotItemCollection
Contents
[
Hide
]PivotItemCollection class
Represents all the PivotItem objects in the PivotField.
public class PivotItemCollection : CollectionBase<PivotItem>
Properties
| Name | Description |
|---|---|
| Capacity { get; set; } | |
| Count { get; } | |
| Item { get; } | Gets the PivotItem Object at the specific index. (2 indexers) |
| Item { get; set; } |
Methods
| Name | Description |
|---|---|
| BinarySearch(PivotItem) | |
| BinarySearch(PivotItem, IComparer<PivotItem>) | |
| BinarySearch(int, int, PivotItem, IComparer<PivotItem>) | |
| ChangeitemsOrder(int, int) | (Obsolete.) Directly changes the orders of the two items. |
| Clear() | |
| Contains(PivotItem) | |
| CopyTo(PivotItem[]) | |
| CopyTo(PivotItem[], int) | |
| CopyTo(int, PivotItem[], int, int) | |
| Exists(Predicate<PivotItem>) | |
| Find(Predicate<PivotItem>) | |
| FindAll(Predicate<PivotItem>) | |
| FindIndex(Predicate<PivotItem>) | |
| FindIndex(int, Predicate<PivotItem>) | |
| FindIndex(int, int, Predicate<PivotItem>) | |
| FindLast(Predicate<PivotItem>) | |
| FindLastIndex(Predicate<PivotItem>) | |
| FindLastIndex(int, Predicate<PivotItem>) | |
| FindLastIndex(int, int, Predicate<PivotItem>) | |
| GetEnumerator() | |
| HideAllDetail(bool) | Sets whether to hide all detail of all PivotItems in a pivot field. That is collapse/expand this field. |
| IndexOf(PivotItem) | |
| IndexOf(PivotItem, int) | |
| IndexOf(PivotItem, int, int) | |
| LastIndexOf(PivotItem) | |
| LastIndexOf(PivotItem, int) | |
| LastIndexOf(PivotItem, int, int) | |
| RemoveAt(int) | |
| SwapItem(int, int) | Directly swap two items. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using Aspose.Cells.Pivot;
using System;
public class PivotItemCollectionDemo
{
public static void PivotItemCollectionExample()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Add some data to the worksheet
worksheet.Cells[0, 0].Value = "Fruit";
worksheet.Cells[1, 0].Value = "Apple";
worksheet.Cells[2, 0].Value = "Banana";
worksheet.Cells[3, 0].Value = "Cherry";
worksheet.Cells[4, 0].Value = "Date";
worksheet.Cells[0, 1].Value = "Quantity";
worksheet.Cells[1, 1].Value = 10;
worksheet.Cells[2, 1].Value = 20;
worksheet.Cells[3, 1].Value = 30;
worksheet.Cells[4, 1].Value = 40;
// Add a pivot table to the worksheet
PivotTableCollection pivotTables = worksheet.PivotTables;
int pivotIndex = pivotTables.Add("=Sheet1!A1:B5", "E3", "PivotTable1");
PivotTable pivotTable = pivotTables[pivotIndex];
// Add fields to the pivot table
pivotTable.AddFieldToArea(PivotFieldType.Row, 0); // Fruit
pivotTable.AddFieldToArea(PivotFieldType.Data, 1); // Quantity
// Access the PivotField and its PivotItems
PivotField pivotField = pivotTable.RowFields[0];
PivotItemCollection pivotItems = pivotField.PivotItems;
// Display the count of pivot items
Console.WriteLine("Pivot Items Count: " + pivotItems.Count);
// Iterate through the pivot items and display their names
foreach (PivotItem item in pivotItems)
{
Console.WriteLine("Pivot Item: " + item.Name);
}
// Change the order of pivot items
pivotItems.ChangeitemsOrder(0, 2);
// Save the workbook
workbook.Save("PivotItemCollectionExample.xlsx");
return;
}
}
}
See Also
- class CollectionBase<T>
- class PivotItem
- namespace Aspose.Cells.Pivot
- assembly Aspose.Cells