Skip to content

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 ​

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:

FieldMeaning
captionThe slicer's caption
cacheNameThe slicer cache
tableName, columnNameThe table and column
styleNamenull without a style
columnCountThe item columns
rowHeightPtThe row height, in points
sortOrderA SlicerSortOrder
crossFilterA SlicerCrossFilter
objectIdThe 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:

KeyDefault
name, captionThe column name
rowHeightPt19 points
columnCount1

Updating a slicer ​

slicer.update(patch) changes these:

KeyChanges
captionThe caption
styleNameThe style; null removes it
columnCountThe item columns
rowHeightPtThe row height
sort order, cross filterThe sort order and the cross filter
description, hidden, anchorThe 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:

ConditionResult
An unknown keyTypeError
null for any key but styleName and descriptionTypeError
An empty styleNameStatusCode.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_slicer
  • fm_sheet_add_slicer, with an fm_slicer_spec_t
  • fm_sheet_update_slicer, with an fm_slicer_patch_t
  • fm_sheet_remove_drawing

The read record is fm_slicer_info_t. The slicers are enumerated with fm_sheet_get_drawing_object_count and _at.