Class Slicer

Slicer

表示一个切片器,用于以非协作方式过滤范围、图表和数据透视表。此类包含用于访问和修改现有切片器的方法。如需创建新的切片器,请使用 Sheet.insertSlicer(range, anchorRowPos, anchorColPos)

方法

方法返回类型简介
getBackgroundColorObject()Color|null返回切片器的背景 Color
getColumnPosition()Integer|null返回切片器中应用过滤条件的列位置(相对于切片器的数据范围),如果未设置列位置,则返回 null
getContainerInfo()ContainerInfo获取有关切片器在工作表中的位置的信息。
getFilterCriteria()FilterCriteria|null返回切片器的过滤条件;如果未设置过滤条件,则返回 null
getRange()Range获取应用切片器的相应数据范围。
getTitle()String返回切片器的标题。
getTitleHorizontalAlignment()String获取标题的水平对齐方式。
getTitleTextStyle()TextStyle返回切片器标题的文字样式。
isAppliedToPivotTables()Boolean返回指定切片器是否应用于数据透视表。
remove()void删除切片器。
setApplyToPivotTables(applyToPivotTables)Slicer设置指定切片器是否应应用于工作表中的数据透视表。
setBackgroundColor(color)Slicer设置切片器的背景颜色。
setBackgroundColorObject(color)Slicer设置切片器的背景 Color
setColumnFilterCriteria(columnPosition, filterCriteria)Slicer设置切片器的列索引和过滤条件。
setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)Slicer设置切片器在工作表上的显示位置。
setRange(rangeApi)Slicer设置应用切片器的数据范围。
setTitle(title)Slicer设置切片器的标题。
setTitleHorizontalAlignment(horizontalAlignment)Slicer设置切片器中标题的水平对齐方式。
setTitleTextStyle(textStyle)Slicer设置切片器的文本样式。

详细文档

getBackgroundColorObject()

返回切片器的背景 Color

返回

Color|null - 此切片器的背景颜色。如果没有设置颜色,则返回 null

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getColumnPosition()

返回切片器中应用过滤条件的列位置(相对于切片器的数据范围),如果未设置列位置,则返回 null。这应是列的从 1 开始的索引位置,与过滤条件类似。

返回

Integer|null - 相应切片器的列位置。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getContainerInfo()

获取有关切片器在工作表中的位置的信息。

返回

ContainerInfo - 包含切片器容器位置的对象。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getFilterCriteria()

返回切片器的过滤条件;如果未设置过滤条件,则返回 null

返回

FilterCriteria|null - 相应切片器的过滤条件。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getRange()

获取应用切片器的相应数据范围。

返回

Range - 切片器范围。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getTitle()

返回切片器的标题。

返回

String - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getTitleHorizontalAlignment()

获取标题的水平对齐方式。

返回

String - 相应切片器标题的水平对齐方式。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

getTitleTextStyle()

返回切片器标题的文字样式。

返回

TextStyle - 相应切片器标题的文字样式。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

isAppliedToPivotTables()

返回指定切片器是否应用于数据透视表。

返回

Boolean - 如果此切片器应用于数据透视表,则为 true,否则为 false

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

remove()

删除切片器。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setApplyToPivotTables(applyToPivotTables)

设置指定切片器是否应应用于工作表中的数据透视表。

参数

名称类型说明
applyToPivotTablesBoolean指定此切片器是否应应用于数据透视表。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setBackgroundColor(color)

设置切片器的背景颜色。值为 null 时,系统会重置背景颜色。

参数

名称类型说明
colorString切片器的新背景颜色(采用 CSS 表示法,例如“#ffffff”)。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setBackgroundColorObject(color)

设置切片器的背景 Color。值为 null 时,系统会重置背景颜色。

参数

名称类型说明
colorColor相应切片器的新背景颜色。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setColumnFilterCriteria(columnPosition, filterCriteria)

设置切片器的列索引和过滤条件。值为 null 时,会重置切片器过滤条件。

参数

名称类型说明
columnPositionInteger相应切片器的新列位置。
filterCriteriaFilterCriteria相应切片器的新过滤条件。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)

设置切片器在工作表上的显示位置。锚定行和列位置索引从 1 开始计数。

参数

名称类型说明
anchorRowPosInteger切片器的顶部固定在此行中。
anchorColPosInteger切片器的顶部固定在此列中。
offsetXInteger单元格角部的水平偏移量(以像素为单位)。
offsetYInteger单元格角部的垂直偏移量(以像素为单位)。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setRange(rangeApi)

设置应用切片器的数据范围。

参数

名称类型说明
rangeApiRange相应切片器的新范围。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setTitle(title)

设置切片器的标题。如果标题为空,则会将标题重置为默认值。

参数

名称类型说明
titleString相应切片器的新标题。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setTitleHorizontalAlignment(horizontalAlignment)

设置切片器中标题的水平对齐方式。值为 null 时,系统会重置对齐方式。

参数

名称类型说明
horizontalAlignmentString相应切片器标题的新水平对齐方式。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

setTitleTextStyle(textStyle)

设置切片器的文本样式。

参数

名称类型说明
textStyleTextStyle切片器标题的新文字样式。

返回

Slicer - 此切片器,用于链式调用。

授权

使用此方法的脚本需要获得以下一项或多项范围的授权:

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

已弃用的方法