Class SlicerCacheItemCollection

SlicerCacheItemCollection class

Represent the collection of SlicerCacheItem

public class SlicerCacheItemCollection : CollectionBase<SlicerCacheItem>

Properties

NameDescription
Capacity { get; set; }
Count { get; }Gets the count of the SlicerCacheItem.
Item { get; }Gets the SlicerCacheItem object by index.
Item { get; set; }

Methods

NameDescription
BinarySearch(SlicerCacheItem)
BinarySearch(SlicerCacheItem, IComparer<SlicerCacheItem>)
BinarySearch(int, int, SlicerCacheItem, IComparer<SlicerCacheItem>)
Clear()
Contains(SlicerCacheItem)
CopyTo(SlicerCacheItem[])
CopyTo(SlicerCacheItem[], int)
CopyTo(int, SlicerCacheItem[], int, int)
Exists(Predicate<SlicerCacheItem>)
Find(Predicate<SlicerCacheItem>)
FindAll(Predicate<SlicerCacheItem>)
FindIndex(Predicate<SlicerCacheItem>)
FindIndex(int, Predicate<SlicerCacheItem>)
FindIndex(int, int, Predicate<SlicerCacheItem>)
FindLast(Predicate<SlicerCacheItem>)
FindLastIndex(Predicate<SlicerCacheItem>)
FindLastIndex(int, Predicate<SlicerCacheItem>)
FindLastIndex(int, int, Predicate<SlicerCacheItem>)
GetEnumerator()
IndexOf(SlicerCacheItem)
IndexOf(SlicerCacheItem, int)
IndexOf(SlicerCacheItem, int, int)
LastIndexOf(SlicerCacheItem)
LastIndexOf(SlicerCacheItem, int)
LastIndexOf(SlicerCacheItem, int, int)
RemoveAt(int)

Examples

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

namespace AsposeCellsExamples
{
    public class SlicersClassSlicerCacheItemCollectionDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            Cells cells = sheet.Cells;

            // Set up sample data
            cells["A1"].Value = "fruit";
            cells["A2"].Value = "grape";
            cells["A3"].Value = "blueberry";
            cells["A4"].Value = "kiwi";
            cells["A5"].Value = "cherry";
            cells["A6"].Value = "grape";
            cells["A7"].Value = "blueberry";
            cells["A8"].Value = "kiwi";
            cells["A9"].Value = "cherry";

            cells["B1"].Value = "year";
            cells["B2"].Value = 2020;
            cells["B3"].Value = 2020;
            cells["B4"].Value = 2020;
            cells["B5"].Value = 2020;
            cells["B6"].Value = 2021;
            cells["B7"].Value = 2021;
            cells["B8"].Value = 2021;
            cells["B9"].Value = 2021;

            cells["C1"].Value = "amount";
            cells["C2"].Value = 50;
            cells["C3"].Value = 60;
            cells["C4"].Value = 70;
            cells["C5"].Value = 80;
            cells["C6"].Value = 90;
            cells["C7"].Value = 100;
            cells["C8"].Value = 110;
            cells["C9"].Value = 120;

            // Create pivot table
            int pivotIndex = sheet.PivotTables.Add("=A1:C9", "A12", "TestPivotTable");
            PivotTable pivot = sheet.PivotTables[pivotIndex];
            pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
            pivot.AddFieldToArea(PivotFieldType.Column, "year");
            pivot.AddFieldToArea(PivotFieldType.Data, "amount");
            pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
            pivot.RefreshData();

            // Add slicer
            int slicerIndex = sheet.Slicers.Add(pivot, "E12", "fruit");
            Slicer slicer = sheet.Slicers[slicerIndex];
            slicer.StyleType = SlicerStyleType.SlicerStyleLight2;

            // Demonstrate SlicerCacheItemCollection usage
            SlicerCacheItemCollection cacheItems = slicer.SlicerCache.SlicerCacheItems;
            Console.WriteLine("Slicer Items Count: " + cacheItems.Count);
            foreach (SlicerCacheItem item in cacheItems)
            {
                Console.WriteLine("Item: " + item.Value + ", Selected: " + item.Selected);
            }

            workbook.Save("SlicerCacheItemCollectionDemo.xlsx");
        }
    }
}

See Also