SlicerCollection

SlicerCollection class

指定指定工作表上所有切片器对象的集合。

public class SlicerCollection : CollectionBase<Slicer>

特性

姓名 描述
Capacity { get; set; }
Count { get; }
Item { get; } 按索引获取切片器。 (2 indexers)
Item { get; set; }

方法

姓名 描述
Add(ListObject, int, string) 使用 ListObjet 作为数据源添加一个新的切片器
Add(ListObject, ListColumn, string) 使用 ListObjet 作为数据源添加一个新的切片器
Add(PivotTable, string, int) 使用数据透视表作为数据源添加一个新的切片器
Add(PivotTable, string, PivotField) 使用数据透视表作为数据源添加一个新的切片器
Add(PivotTable, string, string) 使用数据透视表作为数据源添加一个新的切片器
Add(ListObject, ListColumn, int, int) 使用 ListObjet 作为数据源添加一个新的切片器
Add(PivotTable, int, int, int) 使用数据透视表作为数据源添加一个新的切片器
Add(PivotTable, int, int, PivotField) 使用数据透视表作为数据源添加一个新的切片器
Add(PivotTable, int, int, string) 使用数据透视表作为数据源添加一个新的切片器
BinarySearch(Slicer)
BinarySearch(Slicer, IComparer<Slicer>)
BinarySearch(int, int, Slicer, IComparer<Slicer>)
Clear()
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) 移除指定的 Slicer
RemoveAt(int) 删除指定索引处的切片器 (2 methods)

例子


[C#]

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
Cells cells = sheet.Cells;
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;

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();

SlicerCollection slicers = sheet.Slicers;

int tableIndex = sheet.ListObjects.Add("A1", "C9", true);
ListObject table = sheet.ListObjects[tableIndex];

//做你的事

book.Save("out.xlsx");

[Visual Basic]

Dim book As Workbook = New Workbook()
Dim sheet As Worksheet = book.Worksheets(0)
Dim cells As Cells = sheet.Cells

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

Dim pivots As PivotTableCollection = sheet.PivotTables
Dim pivotIndex As Int32 = pivots.Add("=Sheet1!A1:C9", "A12", "TestPivotTable")
Dim pivot As PivotTable = 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()

Dim slicers As SlicerCollection = sheet.Slicers

Dim tableIndex As Int32 = sheet.ListObjects.Add("A1", "C9", True)
Dim table As ListObject = sheet.ListObjects(tableIndex)

book.Save("out_vb.xlsx")

也可以看看