Excel.Slicer class
Represents a Slicer
object in the workbook.
- Extends
Remarks
Properties
caption | Represents the caption of the slicer. |
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 |
id | Represents the unique ID of the slicer. |
is |
Value is |
left | Represents the distance, in points, from the left side of the slicer to the left of the worksheet. Throws an |
name | Represents the name of the slicer. |
name |
Represents the slicer name used in the formula. |
slicer |
Represents the collection of slicer items that are part of the slicer. |
slicer |
The style applied to the slicer. |
sort |
Represents the sort order of the items in the slicer. Possible values are: "DataSourceOrder", "Ascending", "Descending". |
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. |
top | Represents the distance, in points, from the top edge of the slicer to the top of the worksheet. Throws an |
width | Represents the width, in points, of the slicer. Throws an |
worksheet | Represents the worksheet containing the slicer. |
Methods
clear |
Clears all the filters currently applied on the slicer. |
delete() | Deletes the slicer. |
get |
Returns an array of selected items' keys. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
select |
Selects slicer items based on their keys. The previous selections are cleared. All items will be selected by default if the array is empty. |
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. |
set |
Sets the style applied to the slicer. |
toJSON() | Overrides the JavaScript |
Property Details
caption
Represents the caption of the slicer.
caption: string;
Property Value
string
Remarks
context
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
Represents the height, in points, of the slicer. Throws an InvalidArgument
exception when set with a negative value or zero as an input.
height: number;
Property Value
number
Remarks
id
Represents the unique ID of the slicer.
readonly id: string;
Property Value
string
Remarks
isFilterCleared
Value is true
if all filters currently applied on the slicer are cleared.
readonly isFilterCleared: boolean;
Property Value
boolean
Remarks
left
Represents the distance, in points, from the left side of the slicer to the left of the worksheet. Throws an InvalidArgument
error when set with a negative value as an input.
left: number;
Property Value
number
Remarks
name
Represents the name of the slicer.
name: string;
Property Value
string
Remarks
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.
nameInFormula: string;
Property Value
string
Remarks
slicerItems
Represents the collection of slicer items that are part of the slicer.
readonly slicerItems: Excel.SlicerItemCollection;
Property Value
Remarks
slicerStyle
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 style applied to the slicer.
readonly slicerStyle: Excel.SlicerStyle;
Property Value
Remarks
sortBy
Represents the sort order of the items in the slicer. Possible values are: "DataSourceOrder", "Ascending", "Descending".
sortBy: Excel.SlicerSortType | "DataSourceOrder" | "Ascending" | "Descending";
Property Value
Excel.SlicerSortType | "DataSourceOrder" | "Ascending" | "Descending"
Remarks
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.
style: string;
Property Value
string
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-slicer.yaml
await Excel.run(async (context) => {
const slicer = context.workbook.slicers.getItem("Fruit Slicer");
slicer.style = "SlicerStyleLight6";
await context.sync();
});
top
Represents the distance, in points, from the top edge of the slicer to the top of the worksheet. Throws an InvalidArgument
error when set with a negative value as an input.
top: number;
Property Value
number
Remarks
width
Represents the width, in points, of the slicer. Throws an InvalidArgument
error when set with a negative value or zero as an input.
width: number;
Property Value
number
Remarks
worksheet
Represents the worksheet containing the slicer.
readonly worksheet: Excel.Worksheet;
Property Value
Remarks
Method Details
clearFilters()
Clears all the filters currently applied on the slicer.
clearFilters(): void;
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-slicer.yaml
await Excel.run(async (context) => {
const slicer = context.workbook.slicers.getItem("Fruit Slicer");
slicer.clearFilters();
await context.sync();
});
delete()
Deletes the slicer.
delete(): void;
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-slicer.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
sheet.slicers.getItemAt(0).delete();
await context.sync();
});
getSelectedItems()
Returns an array of selected items' keys.
getSelectedItems(): OfficeExtension.ClientResult<string[]>;
Returns
OfficeExtension.ClientResult<string[]>
Remarks
load(options)
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
Provides options for which properties of the object to load.
Returns
load(propertyNames)
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)
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)
Selects slicer items based on their keys. The previous selections are cleared. All items will be selected by default if the array is empty.
selectItems(items?: string[]): void;
Parameters
- items
-
string[]
Optional. The specified slicer item names to be selected.
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-slicer.yaml
await Excel.run(async (context) => {
const slicer = context.workbook.slicers.getItem("Fruit Slicer");
slicer.selectItems(["Lemon", "Lime", "Orange"]);
await context.sync();
});
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: Interfaces.SlicerUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.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
set(properties)
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
setStyle(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.
Sets the style applied to the slicer.
setStyle(style: string | SlicerStyle | BuiltInSlicerStyle): void;
Parameters
- style
-
string | Excel.SlicerStyle | Excel.BuiltInSlicerStyle
The style to apply to the slicer. An InvalidArgument
error is thrown if a string is provided that does not match the name of any style.
Returns
void
Remarks
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.
toJSON(): Excel.Interfaces.SlicerData;
Returns
Office Add-ins