Class PivotFilterCollection

PivotFilterCollection class

Represents a collection of all the PivotFilter objects

public class PivotFilterCollection : CollectionBase<PivotFilter>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets the pivotfilter object at the specific index.
Item { get; set; }

Methods

NameDescription
Add(int, PivotFilterType)(Obsolete.) Adds a PivotFilter Object to the specific type
AddDateFilter(int, PivotFilterType, DateTime, DateTime)Filters by date setting of row or column pivot field.
AddLabelFilter(int, PivotFilterType, string, string)Filters by captions of row or column pivot field.
AddTop10Filter(int, int, PivotFilterType, bool, int)Filters by values of data pivot field.
AddValueFilter(int, int, PivotFilterType, double, double)Filters by values of data pivot field.
BinarySearch(PivotFilter)
BinarySearch(PivotFilter, IComparer<PivotFilter>)
BinarySearch(int, int, PivotFilter, IComparer<PivotFilter>)
Clear()
ClearFilter(int)Clear PivotFilter from the specific PivotField
Contains(PivotFilter)
CopyTo(PivotFilter[])
CopyTo(PivotFilter[], int)
CopyTo(int, PivotFilter[], int, int)
Exists(Predicate<PivotFilter>)
Find(Predicate<PivotFilter>)
FindAll(Predicate<PivotFilter>)
FindIndex(Predicate<PivotFilter>)
FindIndex(int, Predicate<PivotFilter>)
FindIndex(int, int, Predicate<PivotFilter>)
FindLast(Predicate<PivotFilter>)
FindLastIndex(Predicate<PivotFilter>)
FindLastIndex(int, Predicate<PivotFilter>)
FindLastIndex(int, int, Predicate<PivotFilter>)
GetEnumerator()
IndexOf(PivotFilter)
IndexOf(PivotFilter, int)
IndexOf(PivotFilter, int, int)
LastIndexOf(PivotFilter)
LastIndexOf(PivotFilter, int)
LastIndexOf(PivotFilter, int, int)
RemoveAt(int)

Examples

[C#]

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

    public class PivotFilterCollectionDemo
    {
        public static void PivotFilterCollectionExample()
        {
            // 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 = "Grape";
            worksheet.Cells[2, 0].Value = "Blueberry";
            worksheet.Cells[3, 0].Value = "Kiwi";
            worksheet.Cells[4, 0].Value = "Cherry";
            worksheet.Cells[5, 0].Value = "Grape";
            worksheet.Cells[6, 0].Value = "Blueberry";
            worksheet.Cells[7, 0].Value = "Kiwi";
            worksheet.Cells[8, 0].Value = "Cherry";

            worksheet.Cells[0, 1].Value = "Year";
            worksheet.Cells[1, 1].Value = 2020;
            worksheet.Cells[2, 1].Value = 2020;
            worksheet.Cells[3, 1].Value = 2020;
            worksheet.Cells[4, 1].Value = 2020;
            worksheet.Cells[5, 1].Value = 2021;
            worksheet.Cells[6, 1].Value = 2021;
            worksheet.Cells[7, 1].Value = 2021;
            worksheet.Cells[8, 1].Value = 2021;

            worksheet.Cells[0, 2].Value = "Amount";
            worksheet.Cells[1, 2].Value = 50;
            worksheet.Cells[2, 2].Value = 60;
            worksheet.Cells[3, 2].Value = 70;
            worksheet.Cells[4, 2].Value = 80;
            worksheet.Cells[5, 2].Value = 90;
            worksheet.Cells[6, 2].Value = 100;
            worksheet.Cells[7, 2].Value = 110;
            worksheet.Cells[8, 2].Value = 120;

            // Add a pivot table to the worksheet
            PivotTableCollection pivotTables = worksheet.PivotTables;
            int pivotIndex = pivotTables.Add("=Sheet1!A1:C9", "A12", "PivotTable1");
            PivotTable pivotTable = pivotTables[pivotIndex];

            // Add fields to the pivot table
            pivotTable.AddFieldToArea(PivotFieldType.Row, "Fruit");
            pivotTable.AddFieldToArea(PivotFieldType.Column, "Year");
            pivotTable.AddFieldToArea(PivotFieldType.Data, "Amount");

            // Access the PivotFilterCollection
            PivotFilterCollection pivotFilters = pivotTable.PivotFilters;

            // Add a filter to the pivot table
            int filterIndex = pivotFilters.Add(0, PivotFilterType.Count);
            PivotFilter filter = pivotFilters[filterIndex];

            // Set some properties of the filter
            filter.Value1 = "50";
            filter.Value2 = "100";
            filter.MeasureFldIndex = 2; // Assuming the measure field index is 2

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

See Also