Slicers
A table slicer is a worksheet object that sits beside pictures and charts without holding cell values. This page covers its handle and members; the shared drawing members are in Images and drawings.
What you can do
- List a sheet's slicers and read their properties: Listing slicers.
- Create, update and remove table slicers: Creating a slicer, Updating a slicer, Removing a slicer.
Listing slicers
ws.listSlicers() lists the handles of the table slicers a sheet hosts. A slicer is addressed by its objectId, the id of its frame in the sheet's drawing: ws.slicer(objectId) returns the handle.
slicer.getProperties() returns SlicerProperties:
| Field | Meaning |
|---|---|
caption | The slicer's caption |
cacheName | The slicer cache |
tableName, columnName | The table and column |
styleName | null without a style |
columnCount | The item columns |
rowHeightPt | The row height, in points |
sortOrder | A SlicerSortOrder |
crossFilter | A SlicerCrossFilter |
objectId | The id of its frame in the sheet's drawing |
The name and anchor are read with getDrawingProperties().
The selection itself lives in the table's AutoFilter, not in the slicer. Slicers over a pivot cache pass through a save untouched and are not listed.
Creating a slicer
ws.addSlicer(table, column, spec) creates a slicer over a column of a table (a Table handle or a table name) and returns its Slicer handle. column is a 0-based position or the column's name, resolved as names are, and the table may live on another sheet. It writes the slicer and cache parts, relationships, content types, the Slicer_* defined name, and the drawing frame.
The spec needs a two-cell anchor (fromRow, fromCol, toRow and toCol, or a non-zero size; the offsets default to 0). Other keys default as follows:
| Key | Default |
|---|---|
name, caption | The column name |
rowHeightPt | 19 points |
columnCount | 1 |
Updating a slicer
slicer.update(patch) changes these:
| Key | Changes |
|---|---|
caption | The caption |
styleName | The style; null removes it |
columnCount | The item columns |
rowHeightPt | The row height |
| sort order, cross filter | The sort order and the cross filter |
description, hidden, anchor | The common keys of update |
The name cannot be updated. An objectId, cacheName, tableName or columnName key in the patch is ignored so a getProperties() record can be passed back.
An update fails in these cases:
| Condition | Result |
|---|---|
| An unknown key | TypeError |
null for any key but styleName and description | TypeError |
An empty styleName | StatusCode.InvalidArgument |
Removing a slicer
ws.removeDrawing(slicer) removes the slicer with its frame, removes its cache once no slicer uses it, and drops the sheet's drawing when the slicer was its last object. Removing a table or a sheet, or deleting the rows or columns under a slicer's frame, removes the slicers bound to it the same way.
A loaded slicer survives a resave with all its parts, and its frame moves with row and column edits. A frame that moves without sizing keeps its height and width: a delete covering its top moves it to the first deleted line, as Excel does, and an absolute frame stays where it is.
Slicer saving and bindings
Table slicers loaded from an .xlsx source are not written to .xlsb and are counted in deferredFeatureCount.
Python uses list_slicers(), add_slicer(table, column, SlicerInput(...)) (the anchor is a required DrawingAnchorInput), slicer.update(), and remove_drawing().
The C calls are:
fm_sheet_get_slicerfm_sheet_add_slicer, with anfm_slicer_spec_tfm_sheet_update_slicer, with anfm_slicer_patch_tfm_sheet_remove_drawing
The read record is fm_slicer_info_t. The slicers are enumerated with fm_sheet_get_drawing_object_count and _at.
Read next
- Tables and AutoFilter — the tables a slicer filters.
- Shapes — drawing shapes, text boxes and connectors.
- Sparklines — sparkline groups and their source references.
- Images and drawings — the drawing members shared by every object kind.