Excel.SlicerCollection class
Represents a collection of all the slicer objects in the workbook or a worksheet.
- Extends
Remarks
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(slicer |
Adds a new slicer to the workbook. |
get |
Returns the number of slicers in the collection. |
get |
Gets a slicer object using its name or ID. |
get |
Gets a slicer based on its position in the collection. |
get |
Gets a slicer using its name or ID. If the slicer doesn't exist, then this method returns an object with its |
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 |
toJSON() | Overrides the JavaScript |
Property Details
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
items
Gets the loaded child items in this collection.
readonly items: Excel.Slicer[];
Property Value
Method Details
add(slicerSource, sourceField, slicerDestination)
Adds a new slicer to the workbook.
add(slicerSource: string | PivotTable | Table, sourceField: string | PivotField | number | TableColumn, slicerDestination?: string | Worksheet): Excel.Slicer;
Parameters
- slicerSource
-
string | Excel.PivotTable | Excel.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 or ID of a PivotTable or table.
- sourceField
-
string | Excel.PivotField | number | Excel.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 name or ID of a TableColumn
.
- slicerDestination
-
string | Excel.Worksheet
Optional. The worksheet in which the new slicer will be created. It can be a Worksheet
object or the name or ID of a worksheet. This parameter can be omitted if the slicer collection is retrieved from a worksheet.
Returns
The new slicer.
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.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()
Returns the number of slicers in the collection.
getCount(): OfficeExtension.ClientResult<number>;
Returns
OfficeExtension.ClientResult<number>
Remarks
getItem(key)
Gets a slicer object using its name or ID.
getItem(key: string): Excel.Slicer;
Parameters
- key
-
string
The name or ID of the slicer.
Returns
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.caption = "Fruit Types";
slicer.left = 395;
slicer.top = 15;
slicer.height = 135;
slicer.width = 150;
await context.sync();
});
getItemAt(index)
Gets a slicer based on its position in the collection.
getItemAt(index: number): Excel.Slicer;
Parameters
- index
-
number
Index value of the object to be retrieved. Zero-indexed.
Returns
Remarks
getItemOrNullObject(key)
Gets a slicer using its name or ID. If the slicer doesn't exist, then this method returns an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
getItemOrNullObject(key: string): Excel.Slicer;
Parameters
- key
-
string
Name or ID of the slicer to be retrieved.
Returns
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.SlicerCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.SlicerCollection;
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.SlicerCollection;
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?: OfficeExtension.LoadOption): Excel.SlicerCollection;
Parameters
- propertyNamesAndPaths
- OfficeExtension.LoadOption
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
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.
toJSON(): Excel.Interfaces.SlicerCollectionData;
Returns
Office Add-ins