既存のデータソース テーブルにアクセスして変更します。新しいシートに新しいデータソース テーブルを作成するには、Spreadsheet.insertSheetWithDataSourceTable(spec)
を使用します。
このクラスは、データベースに接続されているデータでのみ使用してください。
この例では、新しいデータソース テーブルを作成する方法を示します。
SpreadsheetApp.enableBigQueryExecution(); var spreadsheet = SpreadsheetApp.getActive(); var spec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('big_query_project') .setRawQuery('select @FIELD from table limit @LIMIT') .setParameterFromCell('FIELD', 'Sheet1!A1') .setParameterFromCell('LIMIT', 'namedRangeCell') .build(); // Starts data execution asynchronously. var dataSheet = spreadsheet.insertSheetWithDataSourceTable(spec); var dataSourceTable = dataSheet.getDataSourceTables()[0]; // waitForCompletion() blocks script execution until data execution completes. dataSourceTable.waitForCompletion(60); // Check status after execution. Logger.log("Data execution state: %s.", dataSourceTable.getStatus().getExecutionState());
この例は、データソースの編集方法を示しています。
SpreadsheetApp.enableBigQueryExecution(); var dataSheet = SpreadsheetApp.getActive().getSheetByName("Data Sheet 1"); var dataSourceTable = dataSheet.getDataSourceTables()[0]; var dataSource = dataSourceTable.getDataSource(); var newSpec = dataSource.getSpec() .copy() .asBigQuery() .setRawQuery('select name from table limit 2') .removeAllParameters() .build(); // Updates data source specification and starts data execution asynchronously. dataSource.updateSpec(newSpec); // Check status during execution. Logger.log("Data execution state: %s.", dataSourceTable.getStatus().getExecutionState()); // waitForCompletion() blocks script execution until data execution completes. dataSourceTable.waitForCompletion(60); // Check status after execution. Logger.log("Data execution state: %s.", dataSourceTable.getStatus().getExecutionState());
方法
詳細なドキュメント
addColumns(columnNames)
データソース テーブルに列を追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
columnNames | String[] | 追加する列の名前のリスト。 |
リターン
DataSourceTable
- チェーン用のデータソース テーブル。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addFilter(columnName, filterCriteria)
データソース テーブルに適用されるフィルタを追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
columnName | String | このフィルタを適用する列の名前。 |
filterCriteria | FilterCriteria | 適用するフィルタ条件。 |
リターン
DataSourceTable
- チェーン用のデータソース テーブル。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addSortSpec(columnName, ascending)
データソース テーブルの列に並べ替え仕様を追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
columnName | String | 並べ替える列の名前。 |
ascending | Boolean | true の場合、列を昇順で並べ替えます。false の場合、列を降順で並べ替えます。 |
リターン
DataSourceTable
- チェーン用のデータソース シート。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addSortSpec(columnName, sortOrder)
データソース テーブルの列に並べ替え仕様を追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
columnName | String | 並べ替える列の名前。 |
sortOrder | SortOrder | 並べ替え順。 |
リターン
DataSourceTable
- チェーン用のデータソース シート。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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()
メソッドを使用します。
リターン
DataSourceTable
- データ オブジェクト。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
forceRefreshData()
現在の状態に関係なく、このオブジェクトのデータを更新します。詳しくは、refreshData()
をご覧ください。このオブジェクトの現在実行中の更新をキャンセルする場合は、cancelDataRefresh()
をご覧ください。
データソース タイプが有効になっていない場合は、例外をスローします。特定のデータソース タイプでデータ実行を有効にするには、SpreadsheetApp#enable...Execution()
メソッドを使用します。
リターン
DataSourceTable
- データ オブジェクト。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getColumns()
データソース テーブルに追加されたすべてのデータソース列を取得します。
リターン
DataSourceTableColumn[]
- データソース テーブルの列のリスト。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSource()
オブジェクトがリンクされているデータソースを取得します。
リターン
DataSource
- データソース。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFilters()
データソースのテーブルに適用されているすべてのフィルタを返します。
リターン
DataSourceTableFilter[]
- データソースのテーブルに適用されるすべてのフィルタの配列。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange()
getRowLimit()
getSortSpecs()
データソース テーブルのすべての並べ替え仕様を取得します。
リターン
SortSpec[]
- 並べ替え仕様のリスト。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getStatus()
オブジェクトのデータ実行ステータスを取得します。
リターン
DataExecutionStatus
- データ実行ステータス。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isSyncingAllColumns()
refreshData()
オブジェクトのデータを更新します。
現在 error
状態の場合は、例外をスローします。DataSource#updateSpec()
を使用して仕様を更新します。データソースで予期しない編集が行われないように、この方法は forceRefreshData()
よりも推奨されています。
データソース タイプが有効になっていない場合は、例外をスローします。特定のデータソース タイプでデータ実行を有効にするには、SpreadsheetApp#enable...Execution()
メソッドを使用します。
リターン
DataSourceTable
- データ オブジェクト。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeAllColumns()
データソース テーブル内のすべての列を削除します。
リターン
DataSourceTable
- チェーン用のデータソース テーブル。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeAllSortSpecs()
データソース テーブルの並べ替え仕様をすべて削除します。
リターン
DataSourceTable
- チェーン用のデータソース シート。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRowLimit(rowLimit)
データソース テーブルの行の上限を更新します。指定された行数の上限が null
の場合は、Google スプレッドシートの UI と同様に、デフォルトの行数の上限を使用するようにデータソース テーブルを更新します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
rowLimit | Integer | データテーブルの新しい行数の上限。null の場合、デフォルトの行数上限を使用するようにテーブルを更新します。 |
リターン
DataSourceTable
- チェーン用のデータソース テーブル。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
syncAllColumns()
関連付けられているデータソースの現在と将来のすべての列を、データソース テーブルに同期します。
リターン
DataSourceTable
- チェーン用のデータソース テーブル。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForCompletion(timeoutInSeconds)
現在の実行が完了するまで待機し、指定された秒数後にタイムアウトします。タイムアウト時に実行が完了していない場合、例外をスローしますが、データ実行はキャンセルされません。
パラメータ
名前 | 型 | 説明 |
---|---|---|
timeoutInSeconds | Integer | データ実行の待機時間(秒)。最大値は 300 秒です。 |
リターン
DataExecutionStatus
- データ実行ステータス。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets