Class PivotAreaCollection

PivotAreaCollection class

Represents a list of pivot area.

public class PivotAreaCollection : CollectionBase<PivotArea>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets a PivotArea object;
Item { get; set; }

Methods

NameDescription
Add(CellArea)Adds an area based on pivot table view.
Add(PivotArea)Adds pivot area.
BinarySearch(PivotArea)
BinarySearch(PivotArea, IComparer<PivotArea>)
BinarySearch(int, int, PivotArea, IComparer<PivotArea>)
Clear()
Contains(PivotArea)
CopyTo(PivotArea[])
CopyTo(PivotArea[], int)
CopyTo(int, PivotArea[], int, int)
Exists(Predicate<PivotArea>)
Find(Predicate<PivotArea>)
FindAll(Predicate<PivotArea>)
FindIndex(Predicate<PivotArea>)
FindIndex(int, Predicate<PivotArea>)
FindIndex(int, int, Predicate<PivotArea>)
FindLast(Predicate<PivotArea>)
FindLastIndex(Predicate<PivotArea>)
FindLastIndex(int, Predicate<PivotArea>)
FindLastIndex(int, int, Predicate<PivotArea>)
GetEnumerator()
IndexOf(PivotArea)
IndexOf(PivotArea, int)
IndexOf(PivotArea, int, int)
LastIndexOf(PivotArea)
LastIndexOf(PivotArea, int)
LastIndexOf(PivotArea, int, int)
RemoveAt(int)Remove one pivot conditional formatted area setting. (2 methods)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Pivot;
    using System;

    public class PivotClassPivotAreaCollectionDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Create sample data for pivot table
            worksheet.Cells["A1"].PutValue("Category");
            worksheet.Cells["B1"].PutValue("Value");
            worksheet.Cells["A2"].PutValue("Electronics");
            worksheet.Cells["B2"].PutValue(1500);
            worksheet.Cells["A3"].PutValue("Clothing");
            worksheet.Cells["B3"].PutValue(800);
            worksheet.Cells["A4"].PutValue("Furniture");
            worksheet.Cells["B4"].PutValue(1200);

            // Add a pivot table
            int pivotIndex = worksheet.PivotTables.Add("A1:B4", "D3", "SalesPivotTable");
            PivotTable pivotTable = worksheet.PivotTables[pivotIndex];

            // Create cell areas for pivot areas
            CellArea dataArea = new CellArea { StartRow = 1, StartColumn = 1, EndRow = 4, EndColumn = 1 };
            CellArea headerArea = new CellArea { StartRow = 0, StartColumn = 0, EndRow = 0, EndColumn = 1 };

            // Get pivot area collection
            PivotAreaCollection pivotAreas = pivotTable.SelectArea(dataArea);

            // Add pivot areas
            pivotAreas.Add(dataArea);
            pivotAreas.Add(headerArea);

            // Display all pivot areas
            Console.WriteLine("Pivot Areas Count: " + pivotAreas.Count);
            for (int i = 0; i < pivotAreas.Count; i++)
            {
                CellArea[] areas = pivotAreas[i].GetCellAreas();
                foreach (CellArea area in areas)
                {
                    Console.WriteLine($"Area {i}: ({area.StartRow},{area.StartColumn}) to ({area.EndRow},{area.EndColumn})");
                }
            }

            // Remove an area
            pivotAreas.RemoveAt(0);
            Console.WriteLine("\nAfter removal - Pivot Areas Count: " + pivotAreas.Count);

            // Save the workbook
            workbook.Save("PivotAreaCollectionDemo.xlsx");
        }
    }
}

See Also