Class SlicerCollection

SlicerCollection class

Specifies the collection of all the Slicer objects on the specified worksheet.

public class SlicerCollection : CollectionBase<Slicer>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets the Slicer by index. (2 indexers)
Item { get; set; }

Methods

NameDescription
Add(ListObject, int, string)Add a new Slicer using ListObjet as data source
Add(ListObject, ListColumn, string)Add a new Slicer using ListObjet as data source
Add(PivotTable, string, int)Add a new Slicer using PivotTable as data source
Add(PivotTable, string, PivotField)Add a new Slicer using PivotTable as data source
Add(PivotTable, string, string)Add a new Slicer using PivotTable as data source
Add(ListObject, ListColumn, int, int)Add a new Slicer using ListObjet as data source
Add(PivotTable, int, int, int)Add a new Slicer using PivotTable as data source
Add(PivotTable, int, int, PivotField)Add a new Slicer using PivotTable as data source
Add(PivotTable, int, int, string)Add a new Slicer using PivotTable as data source
BinarySearch(Slicer)
BinarySearch(Slicer, IComparer<Slicer>)
BinarySearch(int, int, Slicer, IComparer<Slicer>)
Clear()Clear all Slicers. (2 methods)
Contains(Slicer)
CopyTo(Slicer[])
CopyTo(Slicer[], int)
CopyTo(int, Slicer[], int, int)
Exists(Predicate<Slicer>)
Find(Predicate<Slicer>)
FindAll(Predicate<Slicer>)
FindIndex(Predicate<Slicer>)
FindIndex(int, Predicate<Slicer>)
FindIndex(int, int, Predicate<Slicer>)
FindLast(Predicate<Slicer>)
FindLastIndex(Predicate<Slicer>)
FindLastIndex(int, Predicate<Slicer>)
FindLastIndex(int, int, Predicate<Slicer>)
GetEnumerator()
IndexOf(Slicer)
IndexOf(Slicer, int)
IndexOf(Slicer, int, int)
LastIndexOf(Slicer)
LastIndexOf(Slicer, int)
LastIndexOf(Slicer, int, int)
Remove(Slicer)Remove the specified Slicer
RemoveAt(int)Deletes the Slicer at the specified index (2 methods)

Examples

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

    public class SlicerCollectionDemo
    {
        public static void SlicerCollectionExample()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            Cells cells = sheet.Cells;

            // Populate the worksheet with sample data
            cells[0, 0].Value = "fruit";
            cells[1, 0].Value = "grape";
            cells[2, 0].Value = "blueberry";
            cells[3, 0].Value = "kiwi";
            cells[4, 0].Value = "cherry";
            cells[5, 0].Value = "grape";
            cells[6, 0].Value = "blueberry";
            cells[7, 0].Value = "kiwi";
            cells[8, 0].Value = "cherry";

            cells[0, 1].Value = "year";
            cells[1, 1].Value = 2020;
            cells[2, 1].Value = 2020;
            cells[3, 1].Value = 2020;
            cells[4, 1].Value = 2020;
            cells[5, 1].Value = 2021;
            cells[6, 1].Value = 2021;
            cells[7, 1].Value = 2021;
            cells[8, 1].Value = 2021;

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

            // Add a pivot table
            PivotTableCollection pivots = sheet.PivotTables;
            int pivotIndex = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable");
            PivotTable pivot = pivots[pivotIndex];
            pivot.AddFieldToArea(PivotFieldType.Row, "fruit");
            pivot.AddFieldToArea(PivotFieldType.Column, "year");
            pivot.AddFieldToArea(PivotFieldType.Data, "amount");

            pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10;
            pivot.RefreshData();
            pivot.CalculateData();

            // Get the slicer collection
            SlicerCollection slicers = sheet.Slicers;

            // Add a slicer to the worksheet
            int slicerIndex = slicers.Add(pivot, "E2", "fruit");

            // Access the slicer
            Slicer slicer = slicers[slicerIndex];

            // Set some properties of the slicer
            slicer.Caption = "Fruit Slicer";
            slicer.StyleType = SlicerStyleType.SlicerStyleLight1;

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

See Also