Class PivotGroup

PivotGroup

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

方法

方法返回类型简介
addManualGroupingRule(groupName, groupMembers)PivotGroup为此数据透视分组添加手动分组规则。
areLabelsRepeated()Boolean返回标签是否显示为重复。
clearGroupingRule()PivotGroup从此数据透视分组中移除所有分组规则。
clearSort()PivotGroup移除对此群组应用的任何排序。
getDateTimeGroupingRule()DateTimeGroupingRule返回数据透视表的日期时间分组规则,如果未设置日期时间分组规则,则返回 null
getDimension()Dimension返回这是行组还是列组。
getGroupLimit()PivotGroupLimit返回数据透视表元素组的限制。
getIndex()Integer返回此数据透视分组在当前分组顺序中的索引。
getPivotTable()PivotTable返回此分组所属的 PivotTable
getSourceDataColumn()Integer返回此组汇总的源数据列数。
getSourceDataSourceColumn()DataSourceColumn返回数据透视组所处理的数据源列。
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 - 日期时间分组规则。

授权

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

  • 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 - 数据透视表元素组限制。

授权

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

  • 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 - 数据透视组所处理的数据源列。

授权

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

  • 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)

oppositeGroupValues 中的值的指定 PivotValue 对此群组进行排序。

// Sorts the item group by the "SUM of Quantity" pivot value for the specified salespersons.
var sheet = SpreadsheetApp.getActiveSheet();
var pivotTable = sheet.getPivotTables()[0];
var itemGroup = pivotTable.getRowGroups()[0];
var 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