访问和修改现有的数据源工作表。如需创建新的数据源工作表,请使用 Spreadsheet.insertDataSourceSheet(spec)
。
此类只能用于连接到数据库的数据。
方法
详细文档
addFilter(columnName, filterCriteria)
添加应用于数据源工作表的过滤条件。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要应用此过滤条件的列名称。 |
filterCriteria | FilterCriteria | 要应用的过滤条件。 |
返回
DataSourceSheet
- 用于方法链的数据源工作表。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
asSheet()
autoResizeColumn(columnName)
自动调整指定列的宽度。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 列名称。 |
返回
DataSourceSheet
- 此数据源工作表,用于串联。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
autoResizeColumns(columnNames)
自动调整指定列的宽度。
参数
名称 | 类型 | 说明 |
---|---|---|
columnNames | String[] | 要更新的列名称的列表。 |
返回
DataSourceSheet
- 此数据源工作表,用于串联。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
forceRefreshData()
刷新此对象的数据(无论当前状态如何)。如需了解详情,请参阅 refreshData()
。
如果数据源类型未启用,则会抛出异常。使用 SpreadsheetApp#enable...Execution()
方法针对特定数据源类型启用数据执行功能。
返回
DataSourceSheet
- 数据对象。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getColumnWidth(columnName)
返回指定列的宽度。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 列名称。 |
返回
Integer
- 列的宽度;如果列使用默认宽度,则为 null
。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
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()
返回已应用于数据源工作表的所有过滤条件。
返回
DataSourceSheetFilter[]
- 应用于数据源工作表的所有过滤条件的数组。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetValues(columnName)
返回所提供列名称的数据源工作表中的所有值。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要获取其值的数据源列名称。 |
返回
Object[]
- 一维值数组。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetValues(columnName, startRow, numRows)
从提供的起始行(基于 1)到提供的 numRows
,返回所提供列名称的数据源工作表的所有值。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要获取其值的数据源列名称。 |
startRow | Integer | 要开始提取值的行位置。 |
numRows | Integer | 要获取的行数。 |
返回
Object[]
- 一维值数组。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
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
refreshData()
刷新对象的数据。
如果当前处于 error
状态,则会抛出异常。使用 DataSource#updateSpec()
更新规范。此方法优于 forceRefreshData()
,以防止对数据源进行意外修改。
如果数据源类型未启用,则会抛出异常。使用 SpreadsheetApp#enable...Execution()
方法针对特定数据源类型启用数据执行功能。
返回
DataSourceSheet
- 数据对象。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeFilters(columnName)
移除应用于数据源工作表列的所有过滤条件。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要移除过滤条件的列名称。 |
返回
DataSourceSheet
- 用于方法链的数据源工作表。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeSortSpec(columnName)
移除数据源工作表中某列的排序规范。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 列的名称。 |
返回
DataSourceSheet
- 用于串联的数据源工作表。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setColumnWidth(columnName, width)
设置指定列的宽度。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 列名称。 |
width | Integer | 列的新宽度。 |
返回
DataSourceSheet
- 此数据源工作表,用于串联。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setColumnWidths(columnNames, width)
设置指定列的宽度。
参数
名称 | 类型 | 说明 |
---|---|---|
columnNames | String[] | 要更新的列名称的列表。 |
width | Integer | 列的新宽度。 |
返回
DataSourceSheet
- 此数据源工作表,用于串联。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSortSpec(columnName, ascending)
为数据源工作表中的列设置排序规范。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要排序的列名称。 |
ascending | Boolean | 如果为 true ,则按升序对列排序;如果为 false ,则按降序对列排序。 |
返回
DataSourceSheet
- 用于串联的数据源工作表。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSortSpec(columnName, sortOrder)
为数据源工作表中的列设置排序规范。
参数
名称 | 类型 | 说明 |
---|---|---|
columnName | String | 要排序的列名称。 |
sortOrder | SortOrder | 排序顺序。 |
返回
DataSourceSheet
- 用于串联的数据源工作表。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForCompletion(timeoutInSeconds)
等待当前执行完成,在提供的秒数后超时。如果执行超时,但并未取消数据执行,则会抛出异常。
参数
名称 | 类型 | 说明 |
---|---|---|
timeoutInSeconds | Integer | 等待数据执行的时间(以秒为单位)。最大值为 300 秒。 |
返回
DataExecutionStatus
- 数据执行状态。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets