访问和修改现有的数据源公式。如需创建新的数据源公式,请使用 Range.setFormula(formula)
。
此类只能用于连接到数据库的数据。
方法
方法 | 返回类型 | 简介 |
---|---|---|
forceRefreshData() | DataSourceFormula | 刷新此对象的数据(无论当前状态如何)。 |
getAnchorCell() | Range | 返回表示此数据源公式锚定单元格的 Range 。 |
getDataSource() | DataSource | 获取对象所链接的数据源。 |
getDisplayValue() | String | 返回数据源公式的显示值。 |
getFormula() | String | 返回此数据源公式的公式。 |
getStatus() | DataExecutionStatus | 获取对象的数据执行状态。 |
refreshData() | DataSourceFormula | 刷新对象的数据。 |
setFormula(formula) | DataSourceFormula | 更新公式。 |
waitForCompletion(timeoutInSeconds) | DataExecutionStatus | 等待当前执行完成,在提供的秒数后超时。 |
详细文档
forceRefreshData()
刷新此对象的数据(无论当前状态如何)。如需了解详情,请参阅 refreshData()
。
如果数据源类型未启用,则会抛出异常。使用 SpreadsheetApp#enable...Execution()
方法针对特定数据源类型启用数据执行功能。
返回
DataSourceFormula
- 数据对象。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getAnchorCell()
getDataSource()
获取对象所链接的数据源。
返回
DataSource
- 数据源。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDisplayValue()
返回数据源公式的显示值。
返回
String
- 显示值。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormula()
返回此数据源公式的公式。
返回
String
- 公式。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
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()
方法针对特定数据源类型启用数据执行功能。
返回
DataSourceFormula
- 数据对象。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormula(formula)
更新公式。
参数
名称 | 类型 | 说明 |
---|---|---|
formula | String | 新公式。 |
返回
DataSourceFormula
- 用于链接的数据源公式。
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
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