Excel.SlicerCollection class

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Represents a collection of all the slicer objects on the workbook or a worksheet.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

Extends
OfficeExtension.ClientObject

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

items

Gets the loaded child items in this collection.

Methods

add(slicerSource, sourceField, slicerDestination)

Adds a new slicer to the workbook.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getCount()

Returns the number of slicers in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItem(key)

Gets a slicer object using its name or id.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemAt(index)

Gets a slicer based on its position in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemOrNullObject(key)

Gets a slicer using its name or id. If the slicer does not exist, will return a null object.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(option)
toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.SlicerCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SlicerCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

Property Details

context

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

items

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets the loaded child items in this collection.

readonly items: Excel.Slicer[];

Property Value

Method Details

add(slicerSource, sourceField, slicerDestination)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Adds a new slicer to the workbook.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

add(slicerSource: string | PivotTable | Table, sourceField: string | PivotField | number | TableColumn, slicerDestination?: string | Worksheet): Excel.Slicer;

Parameters

slicerSource
string | PivotTable | Table

The data source that the new slicer will be based on. It can be a PivotTable object, a Table object or a string. When a PivotTable object is passed, the data source is the source of the PivotTable object. When a Table object is passed, the data source is the Table object. When a string is passed, it is interpreted as the name/id of a PivotTable/Table.

sourceField
string | PivotField | number | TableColumn

The field in the data source to filter by. It can be a PivotField object, a TableColumn object, the id of a PivotField or the id/name of TableColumn.

slicerDestination
string | Worksheet

Optional. The worksheet where the new slicer will be created in. It can be a Worksheet object or the name/id of a worksheet. This parameter can be omitted if the slicer collection is retrieved from worksheet.

Returns

The new slicer.

Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Pivot");
    const slicer = sheet.slicers.add(
        "Farm Sales", /* The slicer data source. For PivotTables, this can be the PivotTable object reference or name. */
        "Type" /* The field in the data source to filter by. For PivotTables, this can be a PivotField object reference or ID. */
    );
    slicer.name = "Fruit Slicer";
    await context.sync();
});

getCount()

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Returns the number of slicers in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getCount(): OfficeExtension.ClientResult<number>;

Returns

OfficeExtension.ClientResult<number>

getItem(key)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a slicer object using its name or id.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItem(key: string): Excel.Slicer;

Parameters

key
string

The name or id of the slicer.

Returns

Examples

await Excel.run(async (context) => {
    const slicer = context.workbook.slicers.getItem("Fruit Slicer");
    slicer.caption = "Fruit Types";
    slicer.left = 395;
    slicer.top = 15;
    slicer.height = 135;
    slicer.width = 150;
    await context.sync();
});

getItemAt(index)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a slicer based on its position in the collection.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemAt(index: number): Excel.Slicer;

Parameters

index
number

Index value of the object to be retrieved. Zero-indexed.

Returns

getItemOrNullObject(key)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Gets a slicer using its name or id. If the slicer does not exist, will return a null object.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getItemOrNullObject(key: string): Excel.Slicer;

Parameters

key
string

Name or Id of the slicer to be retrieved.

Returns

load(option)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.SlicerCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.SlicerCollection;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.SlicerCollection - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.SlicerCollection - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.SlicerCollection - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.SlicerCollection;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(option)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

load(option?: OfficeExtension.LoadOption): Excel.SlicerCollection;

Parameters

option
OfficeExtension.LoadOption

Returns

toJSON()

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.SlicerCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SlicerCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

toJSON(): Excel.Interfaces.SlicerCollectionData;

Returns