Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handle cell click - Google Spreadsheet - Appscript

Is there a way to mimic the onclick function using google app script?

I already checked online but could not anything in the official documentation, and the only useful post in StackOverflow is the following: How can you monitor for click events in Google Apps script for spreadsheets? but it's an old post from 2013.

Does anyone know if anything changed since then?

like image 988
t97 Avatar asked Oct 19 '25 13:10

t97


1 Answers

Use onSelectionChange trigger:

You can use a simple onSelectionChange trigger for that.

Just add a function named on onSelectionChange and save the project. From now on, every time a different cell is selected, this function will execute.

Code sample:

function onSelectionChange(e) {
  console.log("A NEW CELL WAS SELECTED!");
  console.log(JSON.stringify(e));
}

Note:

  • You might have to refresh the spreadsheet after adding the function, due to this issue.
  • You can get information on which cell was selected by using the corresponding event object, an argument that you can add to Apps Script triggers and which contains information about the event. While the properties of this object are not officially documented yet, you can check those by logging JSON.stringify(e), as shown in the sample above.
like image 160
Iamblichus Avatar answered Oct 22 '25 02:10

Iamblichus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!