Excel.Slicer 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 slicer object in the workbook.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

Extends
OfficeExtension.ClientObject

Properties

caption

Represents the caption of slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

context

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

height

Represents the height, in points, of the slicer. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value or zero as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

id

Represents the unique id of slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

isFilterCleared

True if all filters currently applied on the slicer are cleared.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

left

Represents the distance, in points, from the left side of the slicer to the left of the worksheet. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

name

Represents the name of slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

nameInFormula

Represents the slicer name used in the formula.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

slicerItems

Represents the collection of SlicerItems that are part of the slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

sortBy

Represents the sort order of the items in the slicer. Possible values are: "DataSourceOrder", "Ascending", "Descending".

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

style

Constant value that represents the Slicer style. Possible values are: "SlicerStyleLight1" through "SlicerStyleLight6", "TableStyleOther1" through "TableStyleOther2", "SlicerStyleDark1" through "SlicerStyleDark6". A custom user-defined style present in the workbook can also be specified.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

top

Represents the distance, in points, from the top edge of the slicer to the top of the worksheet. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

width

Represents the width, in points, of the slicer. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value or zero as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

worksheet

Represents the worksheet containing the slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

Methods

clearFilters()

Clears all the filters currently applied on the slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

delete()

Deletes the slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getSelectedItems()

Returns an array of selected items' keys. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

load(options)

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

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

selectItems(items)

Selects slicer items based on their keys. The previous selections are cleared. All items will be selected by default if the array is empty.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

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.Slicer object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SlicerData) that contains shallow copies of any loaded child properties from the original object.

Property Details

caption

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 the caption of slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

caption: string;

Property Value

string

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

height

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 the height, in points, of the slicer. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value or zero as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

height: number;

Property Value

number

id

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 the unique id of slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly id: string;

Property Value

string

isFilterCleared

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.

True if all filters currently applied on the slicer are cleared.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly isFilterCleared: boolean;

Property Value

boolean

left

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 the distance, in points, from the left side of the slicer to the left of the worksheet. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

left: number;

Property Value

number

name

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 the name of slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

name: string;

Property Value

string

nameInFormula

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 the slicer name used in the formula.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

nameInFormula: string;

Property Value

string

slicerItems

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 the collection of SlicerItems that are part of the slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly slicerItems: Excel.SlicerItemCollection;

Property Value

sortBy

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 the sort order of the items in the slicer. Possible values are: "DataSourceOrder", "Ascending", "Descending".

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

sortBy: Excel.SlicerSortType | "DataSourceOrder" | "Ascending" | "Descending";

Property Value

Excel.SlicerSortType | "DataSourceOrder" | "Ascending" | "Descending"

style

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.

Constant value that represents the Slicer style. Possible values are: "SlicerStyleLight1" through "SlicerStyleLight6", "TableStyleOther1" through "TableStyleOther2", "SlicerStyleDark1" through "SlicerStyleDark6". A custom user-defined style present in the workbook can also be specified.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

style: string;

Property Value

string

Examples

await Excel.run(async (context) => {
    const slicer = context.workbook.slicers.getItem("Fruit Slicer");
    slicer.style = "SlicerStyleLight6";
    await context.sync();
});

top

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 the distance, in points, from the top edge of the slicer to the top of the worksheet. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

top: number;

Property Value

number

width

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 the width, in points, of the slicer. Throws an "The argument is invalid or missing or has an incorrect format." exception when set with negative value or zero as input.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

width: number;

Property Value

number

worksheet

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 the worksheet containing the slicer. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly worksheet: Excel.Worksheet;

Property Value

Method Details

clearFilters()

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.

Clears all the filters currently applied on the slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

clearFilters(): void;

Returns

void

Examples

await Excel.run(async (context) => {
    const slicer = context.workbook.slicers.getItem("Fruit Slicer");
    slicer.clearFilters();
    await context.sync();
});

delete()

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.

Deletes the slicer.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

delete(): void;

Returns

void

Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.slicers.getItemAt(0).delete();
    await context.sync();
});

getSelectedItems()

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 an array of selected items' keys. Read-only.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

getSelectedItems(): OfficeExtension.ClientResult<string[]>;

Returns

OfficeExtension.ClientResult<string>[]

load(options)

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(options?: Excel.Interfaces.SlicerLoadOptions): Excel.Slicer;

Parameters

options
Excel.Interfaces.SlicerLoadOptions

Provides options for which properties of the object to load.

Returns

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.Slicer;

Parameters

propertyNames
string | string[]

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

Returns

load(propertyNamesAndPaths)

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(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.Slicer;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

selectItems(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.

Selects slicer items based on their keys. The previous selections are cleared. All items will be selected by default if the array is empty.

[ API set: ExcelApi BETA (PREVIEW ONLY) ]

selectItems(items?: string[]): void;

Parameters

items
string[]

Optional. The specified slicer item names to be selected.

Returns

void

Examples

await Excel.run(async (context) => {
    const slicer = context.workbook.slicers.getItem("Fruit Slicer");
    slicer.selectItems(["Lemon", "Lime", "Orange"]);
    await context.sync();
});

set(properties, options)

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.

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.SlicerUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Interfaces.SlicerUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Excel.Slicer): void

set(properties)

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.

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Slicer): void;

Parameters

properties
Excel.Slicer

Returns

void

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.Slicer object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.SlicerData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.SlicerData;

Returns