既存のデータソース テーブルにアクセスして変更します。新しいシートに新しいデータソース テーブルを作成するには、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());
Methods
詳細なドキュメント
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
forceRefreshData()
現在の状態に関係なく、このオブジェクトのデータを更新します。詳しくは、refreshData()
をご覧ください。
データソース タイプが有効になっていない場合、例外をスローします。特定のデータソース タイプに対してデータ実行を有効にするには、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()
データソース テーブルの行数の上限を返します。
リターン
Integer
- データソース テーブルの行数上限。または、上限が設定されず、テーブルが Google スプレッドシート UI のデフォルトの上限を使用する場合は null
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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()
データソース テーブルが、関連付けられたデータソース内のすべての列を同期しているかどうかを返します。
リターン
Boolean
- データソース テーブルが、関連付けられたデータソース内のすべての列を同期している場合は True
、そうでない場合は false
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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