Class DataSourceSheet  |  Apps Script  |  Google for Developers (original) (raw)

Class DataSourceSheet

Stay organized with collections Save and categorize content based on your preferences.

DataSourceSheet

Access and modify existing data source sheet. To create a new data source sheet, use [Spreadsheet.insertDataSourceSheet(spec)](/apps-script/reference/spreadsheet/spreadsheet#insertDataSourceSheet%28DataSourceSpec%29).

Only use this class with data that's connected to a database.

Detailed documentation

addFilter(columnName, filterCriteria)

Adds a filter applied to the data source sheet.

Parameters

Name Type Description
columnName String The name of the column to apply this filter to.
filterCriteria FilterCriteria The filter criteria to apply.

Return

[DataSourceSheet](#) — The data source sheet, for method chaining.

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


asSheet()

Returns the data source sheet as a regular sheet object.

Return

[Sheet](/apps-script/reference/spreadsheet/sheet) — The regular sheet.

Authorization

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


autoResizeColumn(columnName)

Auto resizes the width of the specified column.

Parameters

Name Type Description
columnName String The 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:


autoResizeColumns(columnNames)

Auto resizes the width of the specified columns.

Parameters

Name Type Description
columnNames String[] 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:


cancelDataRefresh()

Cancels the data refresh associated with this object if it's currently running.

This example shows how to cancel a formula refresh.

const spreadsheet = SpreadsheetApp.getActive(); const formula = spreadsheet.getDataSourceFormulas()[0]; // Cancel the ongoing refresh on the formula. formula.cancelDataRefresh();

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:


forceRefreshData()

Refreshes the data of this object regardless of the current state. See [refreshData()](#refreshData%28%29) for more details. If you want to cancel a currently running refresh of this object, see [cancelDataRefresh()](#cancelDataRefresh%28%29).

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:


getColumnWidth(columnName)

Returns the width of the specified column.

Parameters

Name Type Description
columnName String The 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:


getDataSource()

Gets the data source the object is linked to.

Return

[DataSource](/apps-script/reference/spreadsheet/data-source) — The data source.

Authorization

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


getFilters()

Returns all filters applied to the data source sheet.

Return

[DataSourceSheetFilter[]](/apps-script/reference/spreadsheet/data-source-sheet-filter) — 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:


getSheetValues(columnName)

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

Parameters

Name Type Description
columnName String The 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:


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

Name Type Description
columnName String The data source column name to fetch values for.
startRow Integer The row position to start fetching values from.
numRows Integer The 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:


getSortSpecs()

Gets all the sort specs in the data source sheet.

Return

[SortSpec[]](/apps-script/reference/spreadsheet/sort-spec) — A list of sort specs.

Authorization

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


getStatus()

Gets the data execution status of the object.

Return

[DataExecutionStatus](/apps-script/reference/spreadsheet/data-execution-status) — The data execution status.

Authorization

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


refreshData()

Refreshes the data of the object.

Throws an exception if currently in [error](/apps-script/reference/spreadsheet/data-execution-state#ERROR) state. Use [DataSource#updateSpec()](/apps-script/reference/spreadsheet/data-source#updateSpec%28DataSourceSpec%29) to update the specification. The method is preferred over [forceRefreshData()](#forceRefreshData%28%29) 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:


removeFilters(columnName)

Removes all filters applied to the data source sheet column.

Parameters

Name Type Description
columnName String The 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:


removeSortSpec(columnName)

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

Parameters

Name Type Description
columnName String The 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:


setColumnWidth(columnName, width)

Sets the width of the specified column.

Parameters

Name Type Description
columnName String The column name.
width Integer The 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:


setColumnWidths(columnNames, width)

Sets the width of the specified columns.

Parameters

Name Type Description
columnNames String[] The list of column names to update.
width Integer The 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:


setSortSpec(columnName, ascending)

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

Parameters

Name Type Description
columnName String The name of the column to sort.
ascending Boolean If 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:


setSortSpec(columnName, sortOrder)

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

Parameters

Name Type Description
columnName String The name of the column to sort.
sortOrder SortOrder The 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:


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

Name Type Description
timeoutInSeconds Integer The time to wait for data execution, in seconds. The maximum is 300 seconds.

Return

[DataExecutionStatus](/apps-script/reference/spreadsheet/data-execution-status) — The data execution status.

Authorization

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

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-12-03 UTC.