存取及修改現有資料來源工作表。如要建立新的資料來源工作表,請使用 Spreadsheet.insertDataSourceSheet(spec)。
請只將這個類別用於與資料庫連線的資料。
方法
內容詳盡的說明文件
add Filter(columnName, filterCriteria)
新增套用至資料來源工作表的篩選器。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要套用這個篩選器的資料欄名稱。 |
filter | Filter | 要套用的篩選條件。 |
回攻員
Data - 資料來源工作表,用於方法鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
as Sheet()
auto Resize Column(columnName)
自動調整指定欄的寬度。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料欄名稱。 |
回攻員
Data:這個資料來源工作表,用於串連。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
auto Resize Columns(columnNames)
自動調整指定資料欄的寬度。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String[] | 要更新的資料欄名稱清單。 |
回攻員
Data:這個資料來源工作表,用於串連。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
cancel Data Refresh()
如果與這個物件相關的資料重新整理作業正在執行,系統會取消作業。
這個範例說明如何取消公式重新整理。
const spreadsheet = SpreadsheetApp.getActive(); const formula = spreadsheet.getDataSourceFormulas()[0]; // Cancel the ongoing refresh on the formula. formula.cancelDataRefresh();
如果未啟用資料來源類型,系統會擲回例外狀況。使用 Spreadsheet 方法,為特定資料來源類型啟用資料執行程序。
回攻員
Data:資料物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
force Refresh Data()
無論目前狀態為何,都會重新整理這個物件的資料。詳情請參閱 refresh。如要取消目前正在進行的物件重新整理作業,請參閱 cancel。
如果未啟用資料來源類型,系統會擲回例外狀況。使用 Spreadsheet 方法,為特定資料來源類型啟用資料執行程序。
回攻員
Data:資料物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Column Width(columnName)
傳回指定資料欄的寬度。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料欄名稱。 |
回攻員
Integer|null:資料欄的寬度,或 null (如果資料欄使用預設寬度)。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Data Source()
取得物件連結的資料來源。
回攻員
Data:資料來源。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Filters()
傳回套用至資料來源工作表的所有篩選器。
回攻員
Data:套用至資料來源工作表的所有篩選器陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Sheet Values(columnName)
傳回所提供資料欄名稱的資料來源工作表的所有值。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要擷取值的資料來源資料欄名稱。 |
回攻員
Object[]:一維值陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Sheet Values(columnName, startRow, numRows)
從提供的開始列 (以 1 為基準) 開始,傳回資料來源工作表中指定資料欄名稱的所有值,最多到提供的 num。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要擷取值的資料來源資料欄名稱。 |
start | Integer | 開始擷取值的列位置。 |
num | Integer | 要擷取的資料列數。 |
回攻員
Object[]:一維值陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Sort Specs()
取得資料來源工作表中的所有排序規格。
回攻員
Sort - 排序規格清單。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Status()
取得物件的資料執行狀態。
回攻員
Data - 資料執行狀態。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
refresh Data()
重新整理物件的資料。
如果目前處於 error 狀態,就會擲回例外狀況。使用 Data 更新規格。建議使用這個方法,而非 force,以免資料來源發生預期外的編輯作業。
如果未啟用資料來源類型,系統會擲回例外狀況。使用 Spreadsheet 方法,為特定資料來源類型啟用資料執行程序。
回攻員
Data:資料物件。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Filters(columnName)
移除套用至資料來源工作表欄的所有篩選器。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要移除篩選器的資料欄名稱。 |
回攻員
Data - 資料來源工作表,用於方法鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Sort Spec(columnName)
移除資料來源工作表中的資料欄排序規格。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料欄的名稱。 |
回攻員
Data - 鏈結的資料來源工作表。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Column Width(columnName, width)
設定指定資料欄的寬度。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 資料欄名稱。 |
width | Integer | 資料欄的新寬度。 |
回攻員
Data:這個資料來源工作表,用於串連。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Column Widths(columnNames, width)
設定指定資料欄的寬度。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String[] | 要更新的資料欄名稱清單。 |
width | Integer | 資料欄的新寬度。 |
回攻員
Data:這個資料來源工作表,用於串連。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Sort Spec(columnName, ascending)
在資料來源工作表的資料欄中設定排序規格。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要排序的資料欄名稱。 |
ascending | Boolean | 如果是 true,請以遞增順序排序資料欄;如果是 false,請以遞減順序排序資料欄。 |
回攻員
Data - 鏈結的資料來源工作表。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Sort Spec(columnName, sortOrder)
在資料來源工作表的資料欄中設定排序規格。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
column | String | 要排序的資料欄名稱。 |
sort | Sort | 排序順序。 |
回攻員
Data - 鏈結的資料來源工作表。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
wait For Completion(timeoutInSeconds)
等待目前執行作業完成,並在指定秒數後逾時。 如果執行作業在逾時時未完成,就會擲回例外狀況,但不會取消資料執行作業。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
timeout | Integer | 等待資料執行的時間 (以秒為單位)。最多 300 秒。 |
回攻員
Data - 資料執行狀態。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets