存取及修改現有資料來源資料透視表。如要建立新的資料來源資料透視表,請使用 Range.createDataSourcePivotTable(dataSource)。
請只將這個類別用於與資料庫連線的資料。
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
add | Pivot | 根據指定的資料來源資料欄新增資料透視表資料欄群組。 |
add | Pivot | 根據指定資料來源欄和篩選條件新增篩選器。 |
add | Pivot | 根據指定的資料來源資料欄新增透視值,不使用任何摘要函式。 |
add | Pivot | 根據指定的資料來源資料欄,使用指定的摘要函式新增透視值。 |
add | Pivot | 根據指定的資料來源資料欄,新增資料透視表列群組。 |
as | Pivot | 以一般資料透視表物件的形式傳回資料來源資料透視表。 |
cancel | Data | 如果與這個物件相關的資料重新整理作業正在執行,系統會取消作業。 |
force | Data | 無論目前狀態為何,都會重新整理這個物件的資料。 |
get | Data | 取得物件連結的資料來源。 |
get | Data | 取得物件的資料執行狀態。 |
refresh | Data | 重新整理物件的資料。 |
wait | Data | 等待目前執行作業完成,並在指定秒數後逾時。 |
內容詳盡的說明文件
addColumnGroup(columnName)
根據指定的資料來源資料欄新增資料透視表資料欄群組。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 樞紐群組所依據的資料來源資料欄名稱。 |
回攻員
PivotGroup:新的樞紐群組。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addFilter(columnName, filterCriteria)
根據指定資料來源欄和篩選條件新增篩選器。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 篩選器依據的資料來源資料欄名稱。 |
filter | Filter | 篩選器使用的條件。 |
回攻員
PivotFilter:新篩選器。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addPivotValue(columnName)
根據指定的資料來源資料欄新增透視值,不使用任何摘要函式。僅適用於 Looker 測量值。
以下程式碼說明如何將 Looker 測量指標新增為樞紐分析表值。
// TODO(developer): Replace with your spreadsheet ID which has a Looker data // source. const spreadsheet = SpreadsheetApp.openById('abcd1234'); const datasource = spreadsheet.getDataSources()[0]; const pivotTable = datasource.createDataSourcePivotTableOnNewSheet(); pivotTable.addPivotValue('columnName');
這個方法僅適用於 Looker 資料來源。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料透視值所依據的資料來源資料欄名稱。 |
回攻員
PivotValue:新的樞紐值。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addPivotValue(columnName, summarizeFunction)
根據指定的資料來源資料欄,使用指定的摘要函式新增透視值。
如要為 Looker 測量指標新增樞紐分析表值,請使用 addPivotValue(columnName)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料透視值所依據的資料來源資料欄名稱。 |
summarize | Pivot | 樞紐值使用的摘要函式。 |
回攻員
PivotValue:新的樞紐值。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addRowGroup(columnName)
根據指定的資料來源資料欄,新增資料透視表列群組。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | 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
cancelDataRefresh()
如果與這個物件相關的資料重新整理作業正在執行,系統會取消作業。
這個範例說明如何取消公式重新整理。
const spreadsheet = SpreadsheetApp.getActive(); const formula = spreadsheet.getDataSourceFormulas()[0]; // Cancel the ongoing refresh on the formula. formula.cancelDataRefresh();
如果未啟用資料來源類型,系統會擲回例外狀況。使用 SpreadsheetApp#enable...Execution() 方法,為特定資料來源類型啟用資料執行程序。
回攻員
DataSourcePivotTable:資料物件。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
forceRefreshData()
無論目前狀態為何,都會重新整理這個物件的資料。詳情請參閱 refreshData()。如要取消目前正在進行的物件重新整理作業,請參閱 cancelDataRefresh()。
如果未啟用資料來源類型,系統會擲回例外狀況。使用 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)
等待目前執行作業完成,並在指定秒數後逾時。如果執行作業在逾時時未完成,就會擲回例外狀況,但不會取消資料執行作業。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
timeout | Integer | 等待資料執行的時間 (以秒為單位)。最多 300 秒。 |
回攻員
DataExecutionStatus:資料執行狀態。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets