Class Slicer

Slicer

Represents a slicer, 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 Sheet.insertSlicer(range, anchorRowPos, anchorColPos).

Methods

MethodReturn typeBrief description
getBackgroundColor()StringReturns the background color of the slicer in CSS notation (such as '#ffffff').
getColumnPosition()IntegerReturns 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.
getContainerInfo()ContainerInfoGets information about where the slicer is positioned in the sheet.
getFilterCriteria()FilterCriteriaReturns the filter criteria of the slicer, or null if the filter criteria is not set.
getRange()RangeGets the data range on which the slicer is applied to.
getTitle()StringReturns the title of the slicer.
getTitleHorizontalAlignment()StringGets the horizontal alignment of the title.
getTitleTextStyle()TextStyleReturns the text style of the slicer's title.
isAppliedToPivotTables()BooleanReturns whether the given slicer is applied to pivot tables.
remove()voidDeletes the slicer.
setApplyToPivotTables(applyToPivotTables)SlicerSets if the given slicer should be applied to pivot tables in the worksheet.
setBackgroundColor(color)SlicerSets the background color of the slicer.
setColumnFilterCriteria(columnPosition, filterCriteria)SlicerSets the column index and filtering criteria of the slicer.
setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)SlicerSets the position where the slicer appears on the sheet.
setRange(rangeApi)SlicerSets the data range on which the slicer is applied.
setTitle(title)SlicerSets the title of the slicer.
setTitleHorizontalAlignment(horizontalAlignment)SlicerSets the horizontal alignment of the title in the slicer.
setTitleTextStyle(textStyle)SlicerSets the text style of the slicer.

Detailed documentation

getBackgroundColor()

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

Return

String — The background color of this slicer.

Authorization

Scripts that use this method require authorization with one or more of the following 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 — The column position of this slicer.

Authorization

Scripts that use this method require authorization with one or more of the following 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

ContainerInfo — 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://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

FilterCriteria — The filter criteria of this slicer.

Authorization

Scripts that use this method require authorization with one or more of the following 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

Range — The slicer range.

Authorization

Scripts that use this method require authorization with one or more of the following 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://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://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getTitleTextStyle()

Returns the text style of the slicer's title.

Return

TextStyle — 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://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

isAppliedToPivotTables()

Returns whether the given slicer is applied to pivot tables.

Return

Booleantrue 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://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://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

NameTypeDescription
applyToPivotTablesBooleanSpecifies whether this slicer should apply to pivot tables.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
colorStringThe new background color of this slicer in CSS notation (such as '#ffffff').

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
columnPositionIntegerThe new column position of this slicer.
filterCriteriaFilterCriteriaThe new filter criteria of this slicer.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
anchorRowPosIntegerThe slicer's top side is anchored in this row.
anchorColPosIntegerThe slicer's top side is anchored in this col.
offsetXIntegerThe horizontal offset from cell corner in pixels.
offsetYIntegerThe vertical offset from cell corner in pixels.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
rangeApiRangeThe new range for this slicer.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
titleStringThe new title of this slicer.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following 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

NameTypeDescription
horizontalAlignmentStringThe new horizontal alignment of this slicer's title.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setTitleTextStyle(textStyle)

Sets the text style of the slicer.

Parameters

NameTypeDescription
textStyleTextStyleThe new text style of the slicer's title.

Return

Slicer — This slicer, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets