Class DataSourcePivotTable

DataSourcePivotTable

存取及修改現有的資料來源資料透視表。如要建立新的資料來源資料透視表,請使用 Range.createDataSourcePivotTable(dataSource)

請只搭配已連線至資料庫的資料使用此類別。

方法

方法傳回類型簡短說明
addColumnGroup(columnName)PivotGroup依據指定資料來源欄新增資料透視欄群組。
addFilter(columnName, filterCriteria)PivotFilter根據指定的資料來源欄,以指定的篩選條件新增篩選器。
addPivotValue(columnName, summarizeFunction)PivotValue根據具有指定摘要函式的指定資料來源資料欄,新增資料透視值。
addRowGroup(columnName)PivotGroup依據指定資料來源欄新增資料透視列群組。
asPivotTable()PivotTable以一般的資料透視表物件傳回資料來源資料透視表。
cancelDataRefresh()DataSourcePivotTable如果這個物件正在執行中,則取消相關的資料重新整理作業。
forceRefreshData()DataSourcePivotTable重新整理這個物件的資料,無論目前狀態為何。
getDataSource()DataSource取得物件連結的資料來源。
getStatus()DataExecutionStatus取得物件的資料執行狀態。
refreshData()DataSourcePivotTable重新整理物件資料。
waitForCompletion(timeoutInSeconds)DataExecutionStatus等到目前的執行作業完成,並在指定的秒數過後逾時。

內容詳盡的說明文件

addColumnGroup(columnName)

依據指定資料來源欄新增資料透視欄群組。

參數

名稱類型說明
columnNameString資料透視表依據的資料資料來源資料欄名稱。

回攻員

PivotGroup:新的資料透視表元素群組。

授權

如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:

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

addFilter(columnName, filterCriteria)

根據指定的資料來源欄,以指定的篩選條件新增篩選器。

參數

名稱類型說明
columnNameString篩選器依據的資料產生資料欄名稱。
filterCriteriaFilterCriteria篩選器使用的條件。

回攻員

PivotFilter:新的篩選器。

授權

如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:

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

addPivotValue(columnName, summarizeFunction)

根據具有指定摘要函式的指定資料來源資料欄,新增資料透視值。

參數

名稱類型說明
columnNameString資料導引資料欄的名稱,是資料透視值依據。
summarizeFunctionPivotTableSummarizeFunction資料透視值使用的函式摘要。

回攻員

PivotValue:新的資料透視表值。

授權

如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:

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

addRowGroup(columnName)

依據指定資料來源欄新增資料透視列群組。

參數

名稱類型說明
columnNameString資料透視表依據的資料資料來源資料欄名稱。

回攻員

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)

等到目前的執行作業完成,並在指定的秒數過後逾時。如果執行作業在逾時時未完成,但不取消資料執行,就會擲回例外狀況。

參數

名稱類型說明
timeoutInSecondsInteger等待資料執行的時間 (以秒為單位)。上限為 300 秒。

回攻員

DataExecutionStatus:資料執行狀態。

授權

如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:

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