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)PivotGroup依據 oppositeGroupValues 中的值,以指定的 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要放入 bucket 的項目最大值。大於這個值的值會合併為單一特徵分塊。
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