Slicer

Represents a [slicer](https://support.google.com/docs/answer/9245556), which is used
to filter ranges, charts and pivot tables in a non-collaborative manner. This class contains
methods to access and modify existing slicers. To create a new slicer, use `https://developers.google.com/apps-script/reference/spreadsheet/sheet#insertSlicer(Range,Integer,Integer)`.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getBackgroundColorObject()` | `https://developers.google.com/apps-script/reference/spreadsheet/color|null` | Return the background `https://developers.google.com/apps-script/reference/spreadsheet/color` of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getColumnPosition()` | `Integer|null` | Returns the column position (relative to the data range of the slicer) on which the filter is applied in the slicer, or `null` if the column position is not set. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getContainerInfo()` | `https://developers.google.com/apps-script/reference/spreadsheet/container-info` | Gets information about where the slicer is positioned in the sheet. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getFilterCriteria()` | `https://developers.google.com/apps-script/reference/spreadsheet/filter-criteria|null` | Returns the filter criteria of the slicer, or `null` if the filter criteria is not set. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getRange()` | `https://developers.google.com/apps-script/reference/spreadsheet/range` | Gets the data range on which the slicer is applied to. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getTitle()` | `String` | Returns the title of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getTitleHorizontalAlignment()` | `String` | Gets the horizontal alignment of the title. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getTitleTextStyle()` | `https://developers.google.com/apps-script/reference/spreadsheet/text-style` | Returns the text style of the slicer's title. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#isAppliedToPivotTables()` | `Boolean` | Returns whether the given slicer is applied to pivot tables. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#remove()` | `void` | Deletes the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setApplyToPivotTables(Boolean)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets if the given slicer should be applied to pivot tables in the worksheet. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setBackgroundColor(String)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the background color of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setBackgroundColorObject(Color)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the background `https://developers.google.com/apps-script/reference/spreadsheet/color` of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setColumnFilterCriteria(Integer,FilterCriteria)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the column index and filtering criteria of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setPosition(Integer,Integer,Integer,Integer)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the position where the slicer appears on the sheet. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setRange(Range)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the data range on which the slicer is applied. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setTitle(String)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the title of the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setTitleHorizontalAlignment(String)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the horizontal alignment of the title in the slicer. |
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#setTitleTextStyle(TextStyle)` | `https://developers.google.com/apps-script/reference/spreadsheet/slicer#` | Sets the text style of the slicer. |

### Deprecated methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getBackgroundColor()` | `String|null` | Returns the background color of the slicer in CSS notation (such as '#ffffff'). |

## Detailed documentation

### `getBackgroundColorObject()`

Return the background `https://developers.google.com/apps-script/reference/spreadsheet/color` of the slicer.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/color|null` --- The background color of this slicer. Returns `null` if no color is set.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getColumnPosition()`

Returns the column position (relative to the data range of the slicer) on which the filter is
applied in the slicer, or `null` if the column position is not set. This should be
1-indexed position of the column similar to filter.

#### Return


`Integer|null` --- The column position of this slicer.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getContainerInfo()`

Gets information about where the slicer is positioned in the sheet.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/container-info` --- An object containing the slicer's container position.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getFilterCriteria()`

Returns the filter criteria of the slicer, or `null` if the filter criteria is not set.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/filter-criteria|null` --- The filter criteria of this slicer.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getRange()`

Gets the data range on which the slicer is applied to.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/range` --- The slicer range.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getTitle()`

Returns the title of the slicer.

#### Return


`String` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getTitleHorizontalAlignment()`

Gets the horizontal alignment of the title.

#### Return


`String` --- The horizontal alignment of this slicer's title.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `getTitleTextStyle()`

Returns the text style of the slicer's title.

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/text-style` --- The text style of this slicer's title.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `isAppliedToPivotTables()`

Returns whether the given slicer is applied to pivot tables.

#### Return


`Boolean` --- `true` if this slicer is applied to pivot tables, otherwise `false`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `remove()`

Deletes the slicer.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setApplyToPivotTables(applyToPivotTables)`

Sets if the given slicer should be applied to pivot tables in the worksheet.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `applyToPivotTables` | `Boolean` | Specifies whether this slicer should apply to pivot tables. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setBackgroundColor(color)`

Sets the background color of the slicer. A `null` value resets the background color.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `color` | `String` | The new background color of this slicer in CSS notation (such as '#ffffff'). |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setBackgroundColorObject(color)`

Sets the background `https://developers.google.com/apps-script/reference/spreadsheet/color` of the slicer. A `null` value resets the background
color.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `color` | `https://developers.google.com/apps-script/reference/spreadsheet/color` | The new background color of this slicer. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setColumnFilterCriteria(columnPosition, filterCriteria)`

Sets the column index and filtering criteria of the slicer. A `null` value resets the
slicer filter.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `columnPosition` | `Integer` | The new column position of this slicer. |
| `filterCriteria` | `https://developers.google.com/apps-script/reference/spreadsheet/filter-criteria` | The new filter criteria of this slicer. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)`

Sets the position where the slicer appears on the sheet. The anchor row and column position
indices are 1-indexed.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `anchorRowPos` | `Integer` | The slicer's top side is anchored in this row. |
| `anchorColPos` | `Integer` | The slicer's top side is anchored in this col. |
| `offsetX` | `Integer` | The horizontal offset from cell corner in pixels. |
| `offsetY` | `Integer` | The vertical offset from cell corner in pixels. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setRange(rangeApi)`

Sets the data range on which the slicer is applied.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `rangeApi` | `https://developers.google.com/apps-script/reference/spreadsheet/range` | The new range for this slicer. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setTitle(title)`

Sets the title of the slicer. An empty title resets the title to default value.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `title` | `String` | The new title of this slicer. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setTitleHorizontalAlignment(horizontalAlignment)`

Sets the horizontal alignment of the title in the slicer. A `null` value resets the
alignment.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `horizontalAlignment` | `String` | The new horizontal alignment of this slicer's title. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `setTitleTextStyle(textStyle)`

Sets the text style of the slicer.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `textStyle` | `https://developers.google.com/apps-script/reference/spreadsheet/text-style` | The new text style of the slicer's title. |

#### Return


`https://developers.google.com/apps-script/reference/spreadsheet/slicer#` --- This slicer, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

## Deprecated methods

### `getBackgroundColor()`


**Deprecated.** Replaced by `https://developers.google.com/apps-script/reference/spreadsheet/slicer#getBackgroundColorObject()`

Returns the background color of the slicer in CSS notation (such as '#ffffff').

#### Return


`String|null` --- The background color of this slicer. Returns `null` if no color is set.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`