Class PivotConditionalFormatCollection

PivotConditionalFormatCollection class

Represents all conditional formats of pivot table.

public class PivotConditionalFormatCollection : CollectionBase<PivotConditionalFormat>

Properties

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

Methods

NameDescription
Add()Adds a pivot FormatCondition to the collection.
BinarySearch(PivotConditionalFormat)
BinarySearch(PivotConditionalFormat, IComparer<PivotConditionalFormat>)
BinarySearch(int, int, PivotConditionalFormat, IComparer<PivotConditionalFormat>)
Clear()
Contains(PivotConditionalFormat)
CopyTo(PivotConditionalFormat[])
CopyTo(PivotConditionalFormat[], int)
CopyTo(int, PivotConditionalFormat[], int, int)
Exists(Predicate<PivotConditionalFormat>)
Find(Predicate<PivotConditionalFormat>)
FindAll(Predicate<PivotConditionalFormat>)
FindIndex(Predicate<PivotConditionalFormat>)
FindIndex(int, Predicate<PivotConditionalFormat>)
FindIndex(int, int, Predicate<PivotConditionalFormat>)
FindLast(Predicate<PivotConditionalFormat>)
FindLastIndex(Predicate<PivotConditionalFormat>)
FindLastIndex(int, Predicate<PivotConditionalFormat>)
FindLastIndex(int, int, Predicate<PivotConditionalFormat>)
GetEnumerator()
IndexOf(PivotConditionalFormat)
IndexOf(PivotConditionalFormat, int)
IndexOf(PivotConditionalFormat, int, int)
LastIndexOf(PivotConditionalFormat)
LastIndexOf(PivotConditionalFormat, int)
LastIndexOf(PivotConditionalFormat, int, int)
RemoveAt(int)

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;

namespace AsposeCellsExamples
{
    public class PivotClassPivotConditionalFormatCollectionDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            // Add sample data for pivot table
            Cells cells = sheet.Cells;
            cells["A1"].Value = "Product";
            cells["B1"].Value = "Region";
            cells["C1"].Value = "Sales";
            
            cells["A2"].Value = "A";
            cells["B2"].Value = "East";
            cells["C2"].Value = 100;
            
            cells["A3"].Value = "B";
            cells["B3"].Value = "West";
            cells["C3"].Value = 200;
            
            cells["A4"].Value = "C";
            cells["B4"].Value = "East";
            cells["C4"].Value = 300;
            
            cells["A5"].Value = "D";
            cells["B5"].Value = "West";
            cells["C5"].Value = 400;

            // Create pivot table
            int pivotIndex = sheet.PivotTables.Add("=A1:C5", "E3", "PivotTable1");
            PivotTable pivot = sheet.PivotTables[pivotIndex];
            
            // Add fields to pivot areas
            pivot.AddFieldToArea(PivotFieldType.Row, 0); // Product
            pivot.AddFieldToArea(PivotFieldType.Column, 1); // Region
            pivot.AddFieldToArea(PivotFieldType.Data, 2); // Sales

            // Refresh and calculate pivot table
            pivot.RefreshData();
            pivot.CalculateData();

            // Access conditional formats collection
            PivotConditionalFormatCollection pfcc = pivot.ConditionalFormats;
            int formatIndex = pfcc.Add();
            PivotConditionalFormat pfc = pfcc[formatIndex];
            
            // Get pivot table data range
            CellArea dataBodyRange = pivot.DataBodyRange;
            pfc.FormatConditions.AddArea(dataBodyRange);

            // Add conditional formatting
            FormatConditionCollection fcc = pfc.FormatConditions;
            int conditionIndex = fcc.AddCondition(FormatConditionType.CellValue);
            FormatCondition fc = fcc[conditionIndex];
            fc.Operator = OperatorType.Between;
            fc.Formula1 = "200";
            fc.Formula2 = "400";
            fc.Style.BackgroundColor = System.Drawing.Color.Yellow;

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

See Also