【问题标题】:Get Spreadsheet cell calling a custom function获取调用自定义函数的电子表格单元格
【发布时间】:2018-07-12 17:20:34
【问题描述】:

我正在尝试弄清楚如何获取调用自定义函数的单元格的 A1 表示法。

我找到了这个,但这是针对活动单元格的。 https://webapps.stackexchange.com/questions/54414/in-google-script-get-the-spreadsheet-cell-calling-a-custom-function

基本上,如果我希望单元格 A5 调用 =TEST()。我希望函数返回文本值 A5。

我想将其用作 API 调用的缓存标识符。

【问题讨论】:

  • 你测试了吗?它会正常工作的。

标签: google-apps-script google-sheets


【解决方案1】:

不同的范围返回方法名称存在细微差别-active,current,selection:

The term "active range" refers to the range that a user has selected in the active sheet, but in a custom function it refers to the cell being "active"ly recalculated.

The current cell is the cell that has focus in the Google Sheets UI, and is highlighted by a dark border.

A selection is the set of cells the user has highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the current cell, where the user's current focus is.

前两个仍然是范围对象,而后一个不是。

我希望函数返回文本值 A5。

没有自定义函数,我们可以使用:

=ADDRESS(ROW(),COLUMN())

带有自定义功能,我们可以使用:

function test() { 
 return SpreadsheetApp.getActiveRange().getA1Notation(); 
}

【讨论】:

  • 我想我对“ActiveRange”的事实有点坚持。因为在加载文档时可能需要重新计算该单元格,这会导致该单元格未被用户主动选择。一个单元格可以在没有被选中的情况下处于活动状态吗?它在计算时是否标记为活动?
  • @jef29 自己测试看看。
  • “术语“活动范围”是指用户在活动工作表中选择的范围,但在自定义函数中,它指的是正在重新计算的单元格。 — developers.google.com/apps-script/reference/spreadsheet/…
猜你喜欢
  • 2015-09-21
  • 2021-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多