存取及修改現有的資料來源。如要使用新資料來源建立資料來源資料表,請參閱 DataSourceTable
。
請只搭配已連線至資料庫的資料使用此類別。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
cancelAllLinkedDataSourceObjectRefreshes() | void | 針對與此資料來源連結的資料來源物件,取消所有目前正在執行的重新整理作業。 |
createCalculatedColumn(name, formula) | DataSourceColumn | 建立計算欄。 |
createDataSourcePivotTableOnNewSheet() | DataSourcePivotTable | 在新工作表的第一個儲存格中,以這個資料來源建立資料來源資料透視表。 |
createDataSourceTableOnNewSheet() | DataSourceTable | 在新工作表的第一個儲存格中,根據這個資料來源建立資料來源表格。 |
getCalculatedColumnByName(columnName) | DataSourceColumn | 傳回資料來源中與資料欄名稱相符的計算結果欄。 |
getCalculatedColumns() | DataSourceColumn[] | 傳回資料來源中的所有計算結果欄。 |
getColumns() | DataSourceColumn[] | 傳回資料來源中的所有資料欄。 |
getDataSourceSheets() | DataSourceSheet[] | 傳回與這個資料來源相關聯的資料來源工作表。 |
getSpec() | DataSourceSpec | 取得資料來源規格。 |
refreshAllLinkedDataSourceObjects() | void | 重新整理與資料來源連結的所有資料來源物件。 |
updateSpec(spec) | DataSource | 更新資料來源規格,並重新整理與這個資料來源相連結的資料來源物件,以符合新規格。 |
updateSpec(spec, refreshAllLinkedObjects) | DataSource | 更新資料來源規格,並根據新規格重新整理連結的 data
source sheets 。 |
waitForAllDataExecutionsCompletion(timeoutInSeconds) | void | 等待連結資料來源物件的所有目前執行作業完成,並在提供的秒數過後逾時。 |
內容詳盡的說明文件
cancelAllLinkedDataSourceObjectRefreshes()
針對與此資料來源連結的資料來源物件,取消所有目前正在執行的重新整理作業。
本例說明如何取消資料來源的所有重新整理作業。
SpreadsheetApp.enableBigQueryExecution(); const dataSource = spreadsheet.getDataSources()[0]; dataSource.cancelAllLinkedDataSourceObjectRefreshes();
如果未啟用資料來源類型,就會擲回例外狀況。使用
SpreadsheetApp#enable...Execution()
方法即可為特定資料來源類型啟用資料執行功能。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createCalculatedColumn(name, formula)
建立計算欄。
參數
名稱 | 類型 | 說明 |
---|---|---|
name | String | 計算結果欄的名稱。 |
formula | String | 計算結果欄公式。 |
回攻員
DataSourceColumn
:新建立的計算結果欄。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDataSourcePivotTableOnNewSheet()
在新工作表的第一個儲存格中,以這個資料來源建立資料來源資料透視表。做為副作用,請將新工作表設為使用中的工作表。
回攻員
DataSourcePivotTable
:新建立的資料來源資料透視表。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDataSourceTableOnNewSheet()
在新工作表的第一個儲存格中,根據這個資料來源建立資料來源表格。同時,也會將新的工作表設為使用中的工作表。
回攻員
DataSourceTable
:新建立的資料來源資料表。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getCalculatedColumnByName(columnName)
傳回資料來源中與資料欄名稱相符的計算結果欄。
參數
名稱 | 類型 | 說明 |
---|---|---|
columnName | String | 要取得計算結果的資料欄名稱。 |
回攻員
DataSourceColumn
:與資料欄名稱相符的計算結果資料欄;如果沒有這類計算結果欄,則為 null
。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getCalculatedColumns()
傳回資料來源中的所有計算結果欄。
回攻員
DataSourceColumn[]
:資料來源中所有計算結果欄的陣列。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getColumns()
傳回資料來源中的所有資料欄。
回攻員
DataSourceColumn[]
:資料來源中所有 DataSourceColumn
的陣列。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceSheets()
傳回與這個資料來源相關聯的資料來源工作表。
回攻員
DataSourceSheet[]
:資料來源工作表的陣列。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSpec()
取得資料來源規格。
回攻員
DataSourceSpec
:資料來源規格。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
refreshAllLinkedDataSourceObjects()
重新整理已連結至資料來源的所有資料來源物件。
如果未啟用資料來源類型,就會擲回例外狀況。使用 SpreadsheetApp#enable...Execution()
方法即可為特定資料來源類型啟用資料執行功能。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
updateSpec(spec)
更新資料來源規格,並重新整理與這個資料來源相連結的資料來源物件,以符合新規格。
如果未啟用資料來源類型,就會擲回例外狀況。使用 SpreadsheetApp#enable...Execution()
方法即可為特定資料來源類型啟用資料執行功能。
參數
名稱 | 類型 | 說明 |
---|---|---|
spec | DataSourceSpec | 要更新的資料來源規格。 |
回攻員
DataSource
:資料來源。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
updateSpec(spec, refreshAllLinkedObjects)
更新資料來源規格,並根據新規格重新整理連結的 data
source sheets
。
如果未啟用資料來源類型,就會擲回例外狀況。使用 SpreadsheetApp#enable...Execution()
方法即可為特定資料來源類型啟用資料執行功能。
參數
名稱 | 類型 | 說明 |
---|---|---|
spec | DataSourceSpec | 要更新的資料來源規格。 |
refreshAllLinkedObjects | Boolean | 如果設為 true ,也會重新整理與這個資料來源相連結的所有資料來源物件。 |
回攻員
DataSource
:資料來源。
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForAllDataExecutionsCompletion(timeoutInSeconds)
等待連結資料來源物件的所有目前執行作業完成,並在提供的秒數過後逾時。如果執行作業在逾時時未完成,但不會取消資料執行,就會擲回例外狀況。
參數
名稱 | 類型 | 說明 |
---|---|---|
timeoutInSeconds | Integer | 等待資料執行的時間,以秒為單位。上限為 300 秒。 |
授權
如果指令碼使用這個方法,則必須取得下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets