기존 데이터 소스 표에 액세스하고 수정합니다. 새 시트에 새 데이터 소스 테이블을 만들려면 Spreadsheet.insertSheetWithDataSourceTable(spec)을 사용합니다.
BigQuery 데이터 소스에만 이 클래스를 사용하세요.
이 예에서는 새 데이터 소스 테이블을 만드는 방법을 보여줍니다.
SpreadsheetApp.enableBigQueryExecution(); const spreadsheet = SpreadsheetApp.getActive(); const 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. const dataSheet = spreadsheet.insertSheetWithDataSourceTable(spec); const 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(); const dataSheet = SpreadsheetApp.getActive().getSheetByName('Data Sheet 1'); const dataSourceTable = dataSheet.getDataSourceTables()[0]; const dataSource = dataSourceTable.getDataSource(); const 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)
데이터 소스 테이블에 열을 추가합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
column | String[] | 추가할 열 이름의 목록입니다. |
리턴
DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addFilter(columnName, filterCriteria)
데이터 소스 테이블에 적용된 필터를 추가합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
column | String | 이 필터를 적용할 열의 이름입니다. |
filter | Filter | 적용할 필터 기준입니다. |
리턴
DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addSortSpec(columnName, ascending)
데이터 소스 테이블의 열에 정렬 사양을 추가합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
column | String | 정렬할 열의 이름입니다. |
ascending | Boolean | true인 경우 열을 오름차순으로 정렬하고 false인 경우 열을 내림차순으로 정렬합니다. |
리턴
DataSourceTable - 연결을 위한 데이터 소스 시트입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
addSortSpec(columnName, sortOrder)
데이터 소스 테이블의 열에 정렬 사양을 추가합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
column | String | 정렬할 열의 이름입니다. |
sort | Sort | 정렬 순서입니다. |
리턴
DataSourceTable - 연결을 위한 데이터 소스 시트입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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 - 데이터 객체입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
forceRefreshData()
현재 상태와 관계없이 이 객체의 데이터를 새로고침합니다. 자세한 내용은 refreshData()를 참고하세요. 현재 실행 중인 이 객체의 새로고침을 취소하려면 cancelDataRefresh()를 참고하세요.
데이터 소스 유형이 사용 설정되지 않은 경우 예외를 발생시킵니다. SpreadsheetApp#enable...Execution() 메서드를 사용하여 특정 데이터 소스 유형의 데이터 실행을 사용 설정합니다.
리턴
DataSourceTable - 데이터 객체입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
getColumns()
데이터 소스 테이블에 추가된 모든 데이터 소스 열을 가져옵니다.
리턴
DataSourceTableColumn[] - 데이터 소스 테이블 열 목록입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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
getFilters()
데이터 소스 테이블에 적용된 모든 필터를 반환합니다.
리턴
DataSourceTableFilter[] - 데이터 소스 테이블에 적용된 모든 필터의 배열입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
getRange()
getRowLimit()
데이터 소스 표의 행 제한을 반환합니다.
리턴
Integer|null - 데이터 소스 테이블의 행 제한입니다. 제한이 설정되지 않고 테이블이 Google Sheets UI와 같이 기본 최대 제한을 사용하는 경우 null입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
getSortSpecs()
데이터 소스 테이블의 모든 정렬 사양을 가져옵니다.
리턴
SortSpec[] - 정렬 사양 목록입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
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
isSyncingAllColumns()
데이터 소스 테이블이 연결된 데이터 소스의 모든 열을 동기화하는지 여부를 반환합니다.
리턴
Boolean — 데이터 소스 테이블이 연결된 데이터 소스의 모든 열을 동기화하는 경우 True, 그렇지 않은 경우 false
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
refreshData()
객체의 데이터를 새로고침합니다.
현재 error 상태인 경우 예외를 발생시킵니다. DataSource#updateSpec()를 사용하여 사양을 업데이트합니다. 이 메서드는 데이터 소스의 예기치 않은 수정을 방지하기 위해 forceRefreshData()보다 선호됩니다.
데이터 소스 유형이 사용 설정되지 않은 경우 예외를 발생시킵니다. SpreadsheetApp#enable...Execution() 메서드를 사용하여 특정 데이터 소스 유형의 데이터 실행을 사용 설정합니다.
리턴
DataSourceTable - 데이터 객체입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
removeAllColumns()
데이터 소스 테이블의 모든 열을 삭제합니다.
리턴
DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
removeAllSortSpecs()
데이터 소스 테이블의 모든 정렬 사양을 삭제합니다.
리턴
DataSourceTable - 연결을 위한 데이터 소스 시트입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
setRowLimit(rowLimit)
데이터 소스 표의 행 한도를 업데이트합니다. 제공된 행 제한이 null인 경우 Google Sheets UI에서와 같이 기본 최대 행 제한을 사용하도록 데이터 소스 테이블을 업데이트합니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
row | Integer | 데이터 테이블의 새 행 제한입니다. null인 경우 기본 행 한도를 사용하도록 테이블을 업데이트합니다. |
리턴
DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
syncAllColumns()
연결된 데이터 소스의 현재 및 향후 열을 모두 데이터 소스 테이블에 동기화합니다.
리턴
DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
waitForCompletion(timeoutInSeconds)
현재 실행이 완료될 때까지 기다리며, 제공된 초가 지나면 시간이 초과됩니다. 시간이 초과될 때 실행이 완료되지 않으면 예외를 발생시키지만 데이터 실행을 취소하지는 않습니다.
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
timeout | Integer | 데이터 실행을 기다리는 시간(초)입니다. 최댓값은 300초입니다. |
리턴
DataExecutionStatus - 데이터 실행 상태입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets