Class DataSourceTable

DataSourceTable

기존 데이터 소스 테이블에 액세스하고 수정합니다. 새 시트에 새 데이터 소스 테이블을 만들려면 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)DataSourceTable데이터 소스 테이블에 열을 추가합니다.
addFilter(columnName, filterCriteria)DataSourceTable데이터 소스 표에 적용된 필터를 추가합니다.
addSortSpec(columnName, ascending)DataSourceTable데이터 소스 테이블의 열에 정렬 사양을 추가합니다.
addSortSpec(columnName, sortOrder)DataSourceTable데이터 소스 테이블의 열에 정렬 사양을 추가합니다.
forceRefreshData()DataSourceTable현재 상태에 관계없이 이 객체의 데이터를 새로고침합니다.
getColumns()DataSourceTableColumn[]데이터 소스 테이블에 추가된 모든 데이터 소스 열을 가져옵니다.
getDataSource()DataSource객체가 연결된 데이터 소스를 가져옵니다.
getFilters()DataSourceTableFilter[]데이터 소스 표에 적용된 모든 필터를 반환합니다.
getRange()Range이 데이터 소스 테이블 스팬의 Range를 가져옵니다.
getRowLimit()Integer데이터 소스 테이블의 행 한도를 반환합니다.
getSortSpecs()SortSpec[]데이터 소스 테이블의 모든 정렬 사양을 가져옵니다.
getStatus()DataExecutionStatus객체의 데이터 실행 상태를 가져옵니다.
isSyncingAllColumns()Boolean데이터 소스 테이블이 연결된 데이터 소스의 모든 열을 동기화하는지 여부를 반환합니다.
refreshData()DataSourceTable객체의 데이터를 새로고침합니다.
removeAllColumns()DataSourceTable데이터 소스 테이블의 모든 열을 삭제합니다.
removeAllSortSpecs()DataSourceTable데이터 소스 테이블의 모든 정렬 사양을 삭제합니다.
setRowLimit(rowLimit)DataSourceTable데이터 소스 테이블의 행 한도를 업데이트합니다.
syncAllColumns()DataSourceTable연결된 데이터 소스의 현재 및 향후 열을 모두 데이터 소스 테이블에 동기화합니다.
waitForCompletion(timeoutInSeconds)DataExecutionStatus현재 실행이 완료될 때까지 대기하며 제공된 시간(초)이 지나면 타임아웃됩니다.

자세한 문서

addColumns(columnNames)

데이터 소스 테이블에 열을 추가합니다.

매개변수

이름유형설명
columnNamesString[]추가할 열 이름 목록입니다.

리턴

DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addFilter(columnName, filterCriteria)

데이터 소스 표에 적용된 필터를 추가합니다.

매개변수

이름유형설명
columnNameString이 필터를 적용할 열의 이름입니다.
filterCriteriaFilterCriteria적용할 필터 기준입니다.

리턴

DataSourceTable - 연결을 위한 데이터 소스 테이블입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addSortSpec(columnName, ascending)

데이터 소스 테이블의 열에 정렬 사양을 추가합니다.

매개변수

이름유형설명
columnNameString정렬할 열의 이름입니다.
ascendingBooleantrue이면 열을 오름차순으로 정렬합니다. false이면 열을 내림차순으로 정렬합니다.

리턴

DataSourceTable - 연결용 데이터 소스 시트입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addSortSpec(columnName, sortOrder)

데이터 소스 테이블의 열에 정렬 사양을 추가합니다.

매개변수

이름유형설명
columnNameString정렬할 열의 이름입니다.
sortOrderSortOrder정렬 순서

리턴

DataSourceTable - 연결용 데이터 소스 시트입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

forceRefreshData()

현재 상태에 관계없이 이 객체의 데이터를 새로고침합니다. 자세한 내용은 refreshData()를 참고하세요.

데이터 소스 유형이 사용 설정되지 않은 경우 예외가 발생합니다. 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()

이 데이터 소스 테이블 스팬의 Range를 가져옵니다.

리턴

Range - 범위입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getRowLimit()

데이터 소스 테이블의 행 한도를 반환합니다.

리턴

Integer - 데이터 소스 테이블의 행 한도 또는 한도가 설정되지 않았고 테이블이 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에서와 같이 기본 최대 행 한도를 사용하도록 데이터 소스 테이블을 업데이트합니다.

매개변수

이름유형설명
rowLimitInteger데이터 테이블의 새 행 한도입니다. 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)

현재 실행이 완료될 때까지 대기하며 제공된 시간(초)이 지나면 타임아웃됩니다. 시간 초과 시 실행이 완료되지 않지만 데이터 실행을 취소하지는 않으면 예외가 발생합니다.

매개변수

이름유형설명
timeoutInSecondsInteger데이터 실행을 기다리는 시간(초)입니다. 최댓값은 300초입니다.

리턴

DataExecutionStatus - 데이터 실행 상태입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets