存取及修改現有的資料來源資料透視表。如要建立新的資料來源資料透視表,請使用 Range.createDataSourcePivotTable(dataSource)
。
請僅將這個類別用於連結至資料庫的資料。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
addColumnGroup(columnName) | PivotGroup | 根據指定的資料來源資料欄,新增資料透視表欄群組。 |
addFilter(columnName, filterCriteria) | PivotFilter | 根據指定的資料來源資料欄,新增具有指定篩選條件的篩選器。 |
addPivotValue(columnName, summarizeFunction) | PivotValue | 以指定的匯總函式為基礎,新增資料透視表值。 |
addRowGroup(columnName) | PivotGroup | 根據指定的資料來源資料欄新增資料透視列群組。 |
asPivotTable() | PivotTable | 將資料來源資料透視表傳回為一般的資料透視表物件。 |
forceRefreshData() | DataSourcePivotTable | 重新整理這個物件的資料,無論目前狀態為何。 |
getDataSource() | DataSource | 取得物件連結的資料來源。 |
getStatus() | DataExecutionStatus | 取得物件的資料執行狀態。 |
refreshData() | DataSourcePivotTable | 重新整理物件資料。 |
waitForCompletion(timeoutInSeconds) | DataExecutionStatus | 等到目前的執行作業完成,在提供的秒數後逾時。 |
內容詳盡的說明文件
addColumnGroup(columnName)
根據指定的資料來源資料欄,新增資料透視表欄群組。
參數
名稱 | 類型 | 說明 |
---|---|---|
columnName | String | 資料透視表元素依據的資料欄名稱。 |
回攻員
PivotGroup
:新的資料透視表元素群組,
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addFilter(columnName, filterCriteria)
根據指定的資料來源資料欄,新增具有指定篩選條件的篩選器。
參數
名稱 | 類型 | 說明 |
---|---|---|
columnName | String | 做為篩選器依據的資料簡化資料欄名稱。 |
filterCriteria | FilterCriteria | 篩選器使用的條件。 |
回攻員
PivotFilter
:新的篩選器。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addPivotValue(columnName, summarizeFunction)
以指定的匯總函式為基礎,新增資料透視表值。
參數
名稱 | 類型 | 說明 |
---|---|---|
columnName | String | 依據資料透視值所依據的資料欄命名。 |
summarizeFunction | PivotTableSummarizeFunction | 資料透視值使用的匯總函式。 |
回攻員
PivotValue
— 新的資料透視值。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addRowGroup(columnName)
根據指定的資料來源資料欄新增資料透視列群組。
參數
名稱 | 類型 | 說明 |
---|---|---|
columnName | String | 資料透視表元素依據的資料欄名稱。 |
回攻員
PivotGroup
:新的資料透視表元素群組,
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
asPivotTable()
將資料來源資料透視表傳回為一般的資料透視表物件。
回攻員
PivotTable
:資料透視表。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
forceRefreshData()
重新整理這個物件的資料,無論目前狀態為何。詳情請參閱 refreshData()
。
如果資料來源類型未啟用,就會擲回例外狀況。使用 SpreadsheetApp#enable...Execution()
方法,即可針對特定資料來源類型啟用資料執行功能。
回攻員
DataSourcePivotTable
:資料物件。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSource()
取得物件連結的資料來源。
回攻員
DataSource
:資料來源。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getStatus()
取得物件的資料執行狀態。
回攻員
DataExecutionStatus
:資料執行狀態。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
refreshData()
重新整理物件資料。
如果目前處於 error
狀態,就會擲回例外狀況。請使用 DataSource#updateSpec()
來更新規格。此方法建議優先於 forceRefreshData()
,以免資料來源發生非預期的編輯作業。
如果資料來源類型未啟用,就會擲回例外狀況。使用 SpreadsheetApp#enable...Execution()
方法,即可針對特定資料來源類型啟用資料執行功能。
回攻員
DataSourcePivotTable
:資料物件。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForCompletion(timeoutInSeconds)
等到目前的執行作業完成,在指定的秒數過後逾時。如果執行作業在逾時後未完成,但不會取消資料執行,就會擲回例外狀況。
參數
名稱 | 類型 | 說明 |
---|---|---|
timeoutInSeconds | Integer | 等待資料執行的時間 (以秒為單位)。長度上限為 300 秒。 |
回攻員
DataExecutionStatus
:資料執行狀態。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets