Class PivotTable

数据透视表

访问和修改数据透视表。

方法

方法返回类型简介
addCalculatedPivotValue(name, formula)PivotValue在数据透视表中根据指定的 formula 和指定的 name 创建新的数据透视表值。
addColumnGroup(sourceDataColumn)PivotGroup定义数据透视表中的新数据透视表列分组。
addFilter(sourceDataColumn, filterCriteria)PivotFilter为数据透视表创建新的数据透视过滤条件。
addPivotValue(sourceDataColumn, summarizeFunction)PivotValue在数据透视表中定义具有指定 summarizeFunction 的新数据透视表值。
addRowGroup(sourceDataColumn)PivotGroup定义数据透视表中的新数据透视表行分组。
asDataSourcePivotTable()DataSourcePivotTable如果数据透视表链接到 DataSource,则返回数据透视表作为数据源数据透视表,否则返回 null
getAnchorCell()Range返回表示锚定此数据透视表的单元格的 Range
getColumnGroups()PivotGroup[]返回此数据透视表中列组的有序列表。
getFilters()PivotFilter[]返回此数据透视表中过滤条件的有序列表。
getPivotValues()PivotValue[]返回此数据透视表中数据透视表值的有序列表。
getRowGroups()PivotGroup[]返回此数据透视表中行组的有序列表。
getSourceDataRange()Range返回构建数据透视表时使用的源数据范围。
getValuesDisplayOrientation()Dimension返回值是否以行或列的形式显示。
remove()void删除此数据透视表。
setValuesDisplayOrientation(dimension)PivotTable将此数据透视表的布局设为以列或行的形式显示值。

详细文档

addCalculatedPivotValue(name, formula)

在数据透视表中根据指定的 formula 和指定的 name 创建新的数据透视表值。

参数

名称类型说明
nameString此计算出的数据透视值的名称。
formulaString用于计算此值的公式。

返回

PivotValue - 新创建的 PivotValue

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

addColumnGroup(sourceDataColumn)

定义数据透视表中的新数据透视表列分组。指定的 sourceDataColumn 表示此分组所依据的源数据中的列。

参数

名称类型说明
sourceDataColumnInteger该组汇总的列数。此索引表示电子表格中相应列的绝对数量;1 表示列“A”,2 表示列 B 等。

返回

PivotGroup - 新创建的 PivotGroup

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

addFilter(sourceDataColumn, filterCriteria)

为数据透视表创建新的数据透视过滤条件。指定的 sourceDataColumn 表示此过滤器对源数据中的列进行操作。

参数

名称类型说明
sourceDataColumnInteger该组汇总的列数。此索引表示电子表格中相应列的绝对数量;1 表示列“A”,2 表示列 B 等。
filterCriteriaFilterCriteria用于执行过滤的过滤条件。

返回

PivotFilter - 新创建的 PivotFilter

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

addPivotValue(sourceDataColumn, summarizeFunction)

在数据透视表中定义具有指定 summarizeFunction 的新数据透视表值。指定的 sourceDataColumn 表示此值在源数据中的列。

参数

名称类型说明
sourceDataColumnInteger该组汇总的列数。此索引表示电子表格中相应列的绝对数量;1 表示列“A”,2 表示列 B 等。
summarizeFunctionPivotTableSummarizeFunction

返回

PivotValue - 新创建的 PivotValue

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

addRowGroup(sourceDataColumn)

定义数据透视表中的新数据透视表行分组。指定的 sourceDataColumn 表示此分组所依据的源数据中的列。

参数

名称类型说明
sourceDataColumnInteger该组汇总的列数。此索引表示电子表格中相应列的绝对数量;1 表示列“A”,2 表示列 B 等。

返回

PivotGroup - 新创建的 PivotGroup

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

asDataSourcePivotTable()

如果数据透视表链接到 DataSource,则返回数据透视表作为数据源数据透视表,否则返回 null

返回

DataSourcePivotTable - 数据源数据透视表。

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getAnchorCell()

返回表示锚定此数据透视表的单元格的 Range

返回

Range - 此数据透视表的定位单元格

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getColumnGroups()

返回此数据透视表中列组的有序列表。

返回

PivotGroup[] - 此数据透视表中的列组

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getFilters()

返回此数据透视表中过滤条件的有序列表。

返回

PivotFilter[] - 此数据透视表中的过滤条件

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getPivotValues()

返回此数据透视表中数据透视表值的有序列表。

返回

PivotValue[] - 此数据透视表中的数据透视表值

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getRowGroups()

返回此数据透视表中行组的有序列表。

返回

PivotGroup[] - 此数据透视表中的行组

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getSourceDataRange()

返回构建数据透视表时使用的源数据范围。

返回

Range - 此数据透视表的源数据范围。

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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

getValuesDisplayOrientation()

返回值是否以行或列的形式显示。

返回

Dimension - 值是否显示为行或列

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

  • 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

setValuesDisplayOrientation(dimension)

将此数据透视表的布局设为以列或行的形式显示值。

参数

名称类型说明
dimensionDimension指示如何显示数据透视值的维度。

返回

PivotTable - 用于链接的数据透视表

授权

使用此方法的脚本需要通过以下一个或多个范围进行授权:

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