Slicer class

Slicer class

summary description of Slicer View

The Slicer type exposes the following members:

Properties

PropertyDescription
sort_order_typeIndicates the type of sorting items.
show_missingIndicates whether to show items deteleted from the data source.
show_type_of_items_with_no_dataIndicates whether to show items deteleted from the data source.
show_all_itemsIndicates whether to show all items even if there are no data or they are deleted.
Default value is true;
titleSpecifies the title of the current Slicer object.
alternative_textReturns or sets the descriptive (alternative) text string of the Slicer object.
is_printableIndicates whether the slicer object is printable.
is_lockedIndicates whether the slicer shape is locked.
placementRepresents the way the drawing object is attached to the cells below it.
The property controls the placement of an object on a worksheet.
locked_aspect_ratioIndicates whether locking aspect ratio.
locked_positionIndicates whether the specified slicer can be moved or resized by using the user interface.
shapeReturns the Shape object associated with the specified slicer. Read-only.
slicer_cacheReturns the SlicerCache object associated with the slicer. Read-only.
parentReturns the Slicer.worksheet object which contains this slicer. Read-only.
worksheetReturns the Slicer.worksheet object which contains this slicer. Read-only.
style_typeSpecify the type of Built-in slicer style.
The default type is SlicerStyleLight1.
nameReturns or sets the name of the specified slicer
captionReturns or sets the caption of the specified slicer.
first_item_indexSpecifies the zero-based index of the first slicer item.
caption_visibleReturns or sets whether the header that displays the slicer Caption is visible.
The default value is true
show_captionIndicates whether the header of the slicer is visible.
The default value is true
number_of_columnsReturns or sets the number of columns in the specified slicer.
The default value is 1.
left_pixelReturns or sets the horizontal offset of slicer shape from its left column, in pixels.
top_pixelReturns or sets the vertical offset of slicer shape from its top row, in pixels.
widthReturns or sets the width of the specified slicer, in points.
width_pixelReturns or sets the width of the specified slicer, in pixels.
heightReturns or sets the height of the specified slicer, in points.
height_pixelReturns or sets the height of the specified slicer, in pixels.
column_width_pixelGets or sets the width of each column in the slicer, in unit of pixels.
column_widthReturns or sets the width of each column in the slicer in unit of points.
row_height_pixelReturns or sets the height of each row in the specified slicer, in unit of pixels.
row_heightReturns or sets the height of each row in the specified slicer in unit of points.

Methods

MethodDescription
add_pivot_connection(self, pivot)Adds PivotTable connection.
remove_pivot_connection(self, pivot)Removes PivotTable connection.
refresh(self)Refreshing the slicer.
Meanwhile, Refreshing and Calculating PivotTables which this slicer based on.

Example

from aspose.cells import Workbook
from aspose.cells.pivot import PivotFieldType, PivotTableStyleType
from aspose.cells.slicers import SlicerStyleType

book = Workbook()
sheet = book.worksheets[0]
cells = sheet.cells
cells.get(0, 0).value = "fruit"
cells.get(1, 0).value = "grape"
cells.get(2, 0).value = "blueberry"
cells.get(3, 0).value = "kiwi"
cells.get(4, 0).value = "cherry"
cells.get(5, 0).value = "grape"
cells.get(6, 0).value = "blueberry"
cells.get(7, 0).value = "kiwi"
cells.get(8, 0).value = "cherry"
cells.get(0, 1).value = "year"
cells.get(1, 1).value = 2020
cells.get(2, 1).value = 2020
cells.get(3, 1).value = 2020
cells.get(4, 1).value = 2020
cells.get(5, 1).value = 2021
cells.get(6, 1).value = 2021
cells.get(7, 1).value = 2021
cells.get(8, 1).value = 2021
cells.get(0, 2).value = "amount"
cells.get(1, 2).value = 50
cells.get(2, 2).value = 60
cells.get(3, 2).value = 70
cells.get(4, 2).value = 80
cells.get(5, 2).value = 90
cells.get(6, 2).value = 100
cells.get(7, 2).value = 110
cells.get(8, 2).value = 120
pivots = sheet.pivot_tables
pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable")
pivot = pivots[pivotIndex]
pivot.add_field_to_area(PivotFieldType.ROW, "fruit")
pivot.add_field_to_area(PivotFieldType.COLUMN, "year")
pivot.add_field_to_area(PivotFieldType.DATA, "amount")
pivot.pivot_table_style_type = PivotTableStyleType.PIVOT_TABLE_STYLE_MEDIUM10
pivot.refresh_data()
pivot.calculate_data()
slicers = sheet.slicers
slicerIndex = slicers.add(pivot, "E12", "fruit")
slicer = slicers[slicerIndex]
slicer.style_type = SlicerStyleType.SLICER_STYLE_LIGHT2
items = slicer.slicer_cache.slicer_cache_items
item = items[0]
item.selected = False
# do your business
book.save("out.xlsx")

See Also