Class PivotGroup

透视分组

访问和修改数据透视表细分群组。

方法

方法返回类型简介
addManualGroupingRule(groupName, groupMembers)PivotGroup为此透视组添加手动分组规则。
areLabelsRepeated()Boolean返回标签是否显示为重复。
clearGroupingRule()PivotGroup从相应透视组中移除所有分组规则。
clearSort()PivotGroup移除应用于相应群组的所有排序。
getDateTimeGroupingRule()DateTimeGroupingRule|null返回透视组的日期时间分组规则;如果未设置日期时间分组规则,则返回 null
getDimension()Dimension返回相应组是行组还是列组。
getGroupLimit()PivotGroupLimit|null返回透视组的透视组限制。
getIndex()Integer返回相应透视组在当前组顺序中的索引。
getPivotTable()PivotTable返回相应分组所属的 PivotTable
getSourceDataColumn()Integer返回相应组汇总的源数据列的数量。
getSourceDataSourceColumn()DataSourceColumn|null返回透视组所处理的数据源列。
hideRepeatedLabels()PivotGroup隐藏相应分组的重复标签。
isSortAscending()Boolean如果排序顺序为升序,则返回 true;如果排序顺序为降序,则返回 false
moveToIndex(index)PivotGroup将此组移动到当前行组或列组列表中的指定位置。
remove()void从表格中移除相应透视组。
removeManualGroupingRule(groupName)PivotGroup移除具有指定 groupName 的手动分组规则。
resetDisplayName()PivotGroup将数据透视表中相应群组的显示名称重置为默认值。
setDateTimeGroupingRule(dateTimeGroupingRuleType)PivotGroup为透视组设置日期时间分组规则。
setDisplayName(name)PivotGroup设置透视表中相应组的显示名称。
setGroupLimit(countLimit)PivotGroup设置数据透视表元素组的数据透视表元素组限制。
setHistogramGroupingRule(minValue, maxValue, intervalSize)PivotGroup为此透视组设置直方图分组规则。
showRepeatedLabels()PivotGroup如果存在多个行或列分组,此方法会针对后续分组的每个条目显示相应分组的标签。
showTotals(showTotals)PivotGroup设置是否在表格中显示相应数据透视分组的总值。
sortAscending()PivotGroup将排序顺序设置为升序。
sortBy(value, oppositeGroupValues)PivotGroupoppositeGroupValues 中值的指定 PivotValue 对此组进行排序。
sortDescending()PivotGroup将排序顺序设置为降序。
totalsAreShown()Boolean返回相应透视组是否目前显示总值。

详细文档

addManualGroupingRule(groupName, groupMembers)

为此透视组添加手动分组规则。

参数

名称类型说明
groupNameString相应分组规则的名称。
groupMembersObject[]相应分组规则中包含的值。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

areLabelsRepeated()

返回标签是否显示为重复。

返回

Boolean - 如果标签重复,则为 true;否则返回 false

授权

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

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

clearGroupingRule()

从相应透视组中移除所有分组规则。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

clearSort()

移除应用于相应群组的所有排序。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

getDateTimeGroupingRule()

返回透视组的日期时间分组规则;如果未设置日期时间分组规则,则返回 null

返回

DateTimeGroupingRule|null - 日期时间分组规则。

授权

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

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

getDimension()

返回相应组是行组还是列组。

返回

Dimension - 表示相应组类型的维度

授权

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

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

getGroupLimit()

返回透视组的透视组限制。如果未设置数据透视表元素组限制,则返回 null

返回

PivotGroupLimit|null - 数据透视表元素组限制。

授权

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

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

getIndex()

返回相应透视组在当前组顺序中的索引。

返回

Integer - 透视组的索引

授权

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

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

getPivotTable()

返回相应分组所属的 PivotTable

返回

PivotTable - 此组所属的数据透视表。

授权

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

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

getSourceDataColumn()

返回相应组汇总的源数据列的数量。此索引从 1 开始,如果此组汇总了电子表格中“A”列的源数据,则此方法会返回 1

返回

Integer - 源数据列号

授权

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

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

getSourceDataSourceColumn()

返回透视组所处理的数据源列。如果数据透视表不是 {DataSourcePivotTableApi},则返回 null

返回

DataSourceColumn|null - 数据透视组所处理的数据源列。

授权

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

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

hideRepeatedLabels()

隐藏相应分组的重复标签。如果标签已隐藏,则此方法不会执行任何操作。 如果在有多个行或列分组之前调用此方法,则在添加其他分组时,重复的标签会被隐藏。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

isSortAscending()

如果排序顺序为升序,则返回 true;如果排序顺序为降序,则返回 false

返回

Boolean - true(如果排序顺序为升序)。

授权

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

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

moveToIndex(index)

将此组移动到当前行组或列组列表中的指定位置。这些指数从 0 开始。例如,如果此群组应移至第一个位置,则应使用 0 调用此方法。

参数

名称类型说明
indexInteger要将相应分组移至的索引。

返回

PivotGroup - 用于链接的透视组。

授权

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

  • 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

removeManualGroupingRule(groupName)

移除具有指定 groupName 的手动分组规则。

参数

名称类型说明
groupNameString要移除的分组规则的名称。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

resetDisplayName()

将数据透视表中相应群组的显示名称重置为默认值。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

setDateTimeGroupingRule(dateTimeGroupingRuleType)

设置透视组的日期时间分组规则。

如需移除规则,请使用 clearGroupingRule()

参数

名称类型说明
dateTimeGroupingRuleTypeDateTimeGroupingRuleType要设置的规则类型。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

setDisplayName(name)

设置透视表中相应组的显示名称。

参数

名称类型说明
nameString要设置的显示名称。

返回

PivotGroup - 用于链接的透视组

授权

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

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

setGroupLimit(countLimit)

设置数据透视表元素组的数据透视表元素组限制。此操作仅支持 DataSourcePivotTable

参数

名称类型说明
countLimitInteger要设置的行数或列数上限。必须为正值。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

setHistogramGroupingRule(minValue, maxValue, intervalSize)

为此透视组设置直方图分组规则。直方图规则会将源数据列中的值整理到大小恒定的桶中。从 minValuemaxValue 的所有值都将放入大小为 interval 的组中。所有低于 minValue 的值以及所有高于 maxValue 的值都将放入一个分桶中。

参数

名称类型说明
minValueInteger商品归入相应分桶的最低价值。小于此值的值会合并到一个分桶中。
maxValueInteger要放入分桶中的商品的最大值。大于此值的值会合并到一个分桶中。
intervalSizeInteger

返回

PivotGroup - 用于链接的透视组。

授权

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

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

showRepeatedLabels()

如果存在多个行或列分组,此方法会针对后续分组的每个条目显示相应分组的标签。如果标签已重复,则此方法不会执行任何操作。如果此方法是在存在多个行或列分组之前调用的,那么在添加其他分组时,系统会显示重复的标签。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

showTotals(showTotals)

设置是否在表格中显示相应数据透视分组的总值。

参数

名称类型说明
showTotalsBoolean是否显示总计。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

sortAscending()

将排序顺序设置为升序。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

sortBy(value, oppositeGroupValues)

按指定 PivotValue 对来自 oppositeGroupValues 的值进行排序。

// Sorts the item group by the "SUM of Quantity" pivot value for the specified
// salespersons.
const sheet = SpreadsheetApp.getActiveSheet();
const pivotTable = sheet.getPivotTables()[0];
const itemGroup = pivotTable.getRowGroups()[0];
const sumQuantityValue = pivotTable.getPivotValues()[0];
itemGroup.sortBy(sumQuantityValue, ['Beth', 'Amir', 'Devyn']);

参数

名称类型说明
valuePivotValue要排序的数据透视值。
oppositeGroupValuesObject[]用于排序的相反透视组(如果对行组进行排序,则为列组;如果对列组进行排序,则为行组)的值。这些值的顺序决定了打破平局的优先级。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

sortDescending()

将排序顺序设置为降序。

返回

PivotGroup - 用于链接的透视组。

授权

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

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

totalsAreShown()

返回相应透视组是否目前显示总值。

返回

Boolean - 如果显示相应透视组的总值,则为 true;否则为 false

授权

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

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