获取调用自定义函数的电子表格单元格

时间:2018-07-12 17:20:34

标签: google-apps-script google-sheets

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

我发现了这个,但这是针对活动细胞的。 https://webapps.stackexchange.com/questions/54414/in-google-script-get-the-spreadsheet-cell-calling-a-custom-function

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

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

1 个答案:

答案 0 :(得分:4)

不同的范围返回方法名称之间存在细微差异-activecurrentselection

  

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(); 
}