Google app script monitor spreadsheet selected ranges

前端 未结 2 738
耶瑟儿~
耶瑟儿~ 2021-01-28 05:11

I want to write a app script that can get the selected cells

and show it on the html input text.

example:

when I selected A1 cell, then the input text wi

2条回答
  •  -上瘾入骨i
    2021-01-28 05:41

    New event added in April 2020:

    Ref: https://developers.google.com/apps-script/guides/triggers#onselectionchangee

    /**
     * The event handler triggered when the selection changes in the spreadsheet.
     * @param {Event} e The onSelectionChange event.
     */
    function onSelectionChange(e) {
      // Set background to red if a single empty cell is selected.
      var range = e.range;
      if(range.getNumRows() === 1 
          && range.getNumColumns() === 1 
          && range.getCell(1, 1).getValue() === "") {
        range.setBackground("red");
      }
    }
    

提交回复
热议问题