Class DataSourceFormula

DataSourceFormula

访问和修改现有数据源公式。如需创建新的数据源公式,请使用 Range.setFormula(formula)

请仅将此类与连接到 BigQuery 数据库的数据搭配使用。

方法

方法返回值类型简介
cancelDataRefresh()DataSourceFormula取消与此对象关联的数据刷新(如果当前正在运行)。
forceRefreshData()DataSourceFormula无论当前状态如何,都会刷新此对象的数据。
getAnchorCell()Range返回 Range,表示此数据源公式所锚定的单元格。
getDataSource()DataSource获取对象所链接到的数据源。
getDisplayValue()String返回数据源公式的显示值。
getFormula()String返回此数据源公式的公式。
getStatus()DataExecutionStatus获取对象的数据执行状态。
refreshData()DataSourceFormula刷新对象的数据。
setFormula(formula)DataSourceFormula更新公式。
waitForCompletion(timeoutInSeconds)DataExecutionStatus等待当前执行完成,并在指定秒数后超时。

详细文档

cancelDataRefresh()

取消与此对象关联的数据刷新(如果当前正在运行)。

此示例展示了如何取消公式刷新。

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

如果未启用数据源类型,则会抛出异常。使用 SpreadsheetApp#enable...Execution() 方法为特定数据源类型启用数据执行。

返回

DataSourceFormula - 数据对象。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

forceRefreshData()

无论当前状态如何,都会刷新此对象的数据。如需了解详情,请参阅 refreshData()。如果您想取消当前正在运行的此对象刷新,请参阅 cancelDataRefresh()

如果未启用数据源类型,则会抛出异常。使用 SpreadsheetApp#enable...Execution() 方法为特定数据源类型启用数据执行。

返回

DataSourceFormula - 数据对象。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

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

getAnchorCell()

返回 Range,表示此数据源公式所锚定的单元格。

返回

Range - 锚定单元格。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • 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

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)

更新公式。

参数

名称类型说明
formulaString新公式。

返回

DataSourceFormula - 数据源公式,用于链接。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • 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