Google is committed to advancing racial equity for Black communities. See how.

Class DataSourceSheet

DataSourceSheet

Access and modify existing data source sheet. To create a new data source sheet, use Spreadsheet.insertDataSourceSheet(spec).

Methods

MethodReturn typeBrief description
addFilter(columnName, filterCriteria)DataSourceSheetAdds a filter applied to the data source sheet.
asSheet()SheetReturns the data source sheet as a regular sheet object.
autoResizeColumn(columnName)DataSourceSheetAuto resizes the width of the specified column.
autoResizeColumns(columnNames)DataSourceSheetAuto resizes the width of the specified columns.
forceRefreshData()DataSourceSheetRefreshes the data of this object regardless of the current state.
getColumnWidth(columnName)IntegerReturns the width of the specified column.
getDataSource()DataSourceGets the data source the object is linked to.
getFilters()DataSourceSheetFilter[]Returns all filters applied to the data source sheet.
getSheetValues(columnName)Object[]Returns all the values for the data source sheet for the provided column name.
getSheetValues(columnName, startRow, numRows)Object[]Returns all the values for the data source sheet for the provided column name from the provided start row (based-1) and up to the provided numRows.
getSortSpecs()SortSpec[]Gets all the sort specs in the data source sheet.
getStatus()DataExecutionStatusGets the data execution status of the object.
refreshData()DataSourceSheetRefreshes the data of the object.
removeFilters(columnName)DataSourceSheetRemoves all filters applied to the data source sheet column.
removeSortSpec(columnName)DataSourceSheetRemoves the sort spec on a column in the data source sheet.
setColumnWidth(columnName, width)DataSourceSheetSets the width of the specified column.
setColumnWidths(columnNames, width)DataSourceSheetSets the width of the specified columns.
setSortSpec(columnName, ascending)DataSourceSheetSets the sort spec on a column in the data source sheet.
setSortSpec(columnName, sortOrder)DataSourceSheetSets the sort spec on a column in the data source sheet.
waitForCompletion(timeoutInSeconds)DataExecutionStatusWaits until the current execution completes, timing out after the provided number of seconds.

Detailed documentation

addFilter(columnName, filterCriteria)

Adds a filter applied to the data source sheet.

Parameters

NameTypeDescription
columnNameStringThe name of the column to apply this filter to.
filterCriteriaFilterCriteriaThe filter criteria to apply.

Return

DataSourceSheet — The data source sheet, for method chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

asSheet()

Returns the data source sheet as a regular sheet object.

Return

Sheet — The regular sheet.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

autoResizeColumn(columnName)

Auto resizes the width of the specified column.

Parameters

NameTypeDescription
columnNameStringThe column name.

Return

DataSourceSheet — This data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

autoResizeColumns(columnNames)

Auto resizes the width of the specified columns.

Parameters

NameTypeDescription
columnNamesString[]The list of column names to update.

Return

DataSourceSheet — This data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

forceRefreshData()

Refreshes the data of this object regardless of the current state. See refreshData() for more details.

Throws an exception if the data source type is not enabled. Use SpreadsheetApp#enable...Execution() methods to enable data execution for specific data source type.

Return

DataSourceSheet — The data object.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getColumnWidth(columnName)

Returns the width of the specified column.

Parameters

NameTypeDescription
columnNameStringThe column name.

Return

Integer — The column's width, or null if the column uses the default width.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getDataSource()

Gets the data source the object is linked to.

Return

DataSource — The data source.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getFilters()

Returns all filters applied to the data source sheet.

Return

DataSourceSheetFilter[] — An array of all filters applied to the data source sheet.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getSheetValues(columnName)

Returns all the values for the data source sheet for the provided column name.

Parameters

NameTypeDescription
columnNameStringThe data source column name to fetch values for.

Return

Object[] — A one-dimensional array of values.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getSheetValues(columnName, startRow, numRows)

Returns all the values for the data source sheet for the provided column name from the provided start row (based-1) and up to the provided numRows.

Parameters

NameTypeDescription
columnNameStringThe data source column name to fetch values for.
startRowIntegerThe row position to start fetching values from.
numRowsIntegerThe number of rows to fetch.

Return

Object[] — A one-dimensional array of values.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getSortSpecs()

Gets all the sort specs in the data source sheet.

Return

SortSpec[] — A list of sort specs.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

getStatus()

Gets the data execution status of the object.

Return

DataExecutionStatus — The data execution status.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

refreshData()

Refreshes the data of the object.

Throws an exception if currently in error state. Use DataSource#updateSpec() to update the specification. The method is preferred over forceRefreshData() to prevent unexpected edits on data source.

Throws an exception if the data source type is not enabled. Use SpreadsheetApp#enable...Execution() methods to enable data execution for specific data source type.

Return

DataSourceSheet — The data object.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

removeFilters(columnName)

Removes all filters applied to the data source sheet column.

Parameters

NameTypeDescription
columnNameStringThe name of the column to remove filters from.

Return

DataSourceSheet — The data source sheet, for method chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

removeSortSpec(columnName)

Removes the sort spec on a column in the data source sheet.

Parameters

NameTypeDescription
columnNameStringThe name of the column.

Return

DataSourceSheet — The data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setColumnWidth(columnName, width)

Sets the width of the specified column.

Parameters

NameTypeDescription
columnNameStringThe column name.
widthIntegerThe new width for the column.

Return

DataSourceSheet — This data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setColumnWidths(columnNames, width)

Sets the width of the specified columns.

Parameters

NameTypeDescription
columnNamesString[]The list of column names to update.
widthIntegerThe new width for the columns.

Return

DataSourceSheet — This data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setSortSpec(columnName, ascending)

Sets the sort spec on a column in the data source sheet.

Parameters

NameTypeDescription
columnNameStringThe name of the column to sort.
ascendingBooleanIf true, sort the column in ascending order; if false, sort the column in descending order.

Return

DataSourceSheet — The data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

setSortSpec(columnName, sortOrder)

Sets the sort spec on a column in the data source sheet.

Parameters

NameTypeDescription
columnNameStringThe name of the column to sort.
sortOrderSortOrderThe sort order.

Return

DataSourceSheet — The data source sheet, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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

waitForCompletion(timeoutInSeconds)

Waits until the current execution completes, timing out after the provided number of seconds. Throws an exception if the execution is not completed when timing out, but does not cancel the data execution.

Parameters

NameTypeDescription
timeoutInSecondsIntegerThe time to wait for data execution, in seconds. The maximum is 300 seconds.

Return

DataExecutionStatus — The data execution status.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

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