在选择单元格时触发功能

时间:2018-11-06 11:23:08

标签: google-apps-script google-sheets triggers google-sheets-api

如何编写触发器,该触发器在用户每次选择任何单元格时都会触发。触发器将调用一个函数,该函数将在Google Apps脚本上记录突出显示的单元格的行号

我已经编写了一个用于执行此操作的函数

function getCell() {
  var app = SpreadsheetApp;
  var ss = app.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //get the current highlighted cell
  var cell = sheet.getCurrentCell();

  //get the row number
  var row = cell.getRow(); 

  //log the value
  Logger.log(row);

}

但是我不知道如何编写触发器。当前,每次单击其他单元格时,我都必须运行脚本。

2 个答案:

答案 0 :(得分:1)

奇怪,它第一次起作用。...

function onSelectionChange(e){
   Browser.msgBox('cell selection change');
}

自问题发布以来,情况可能发生了变化,但落在此处。

答案 1 :(得分:0)

https://developers.google.com/apps-script/guides/triggers/中描述了可用的触发器。可以解决的另一种方法是使用How do I make a Sidebar display values from cells?

中描述的“轮询技术”