简体   繁体   English

处理单元格点击 - Google 电子表格 - Appscript

[英]handle cell click - Google Spreadsheet - Appscript

Is there a way to mimic the onclick function using google app script?有没有办法使用谷歌应用脚本模仿onclick function ?

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?我已经在网上查过了,但在官方文档中什么也查不到,StackOverflow 中唯一有用的帖子如下: 如何在电子表格的 Google Apps 脚本中监控点击事件? but it's an old post from 2013.但这是2013年的旧帖子。

Does anyone know if anything changed since then?有谁知道从那以后有什么变化吗?

Use onSelectionChange trigger:使用 onSelectionChange 触发器:

You can use a simple onSelectionChange trigger for that.您可以为此使用简单的onSelectionChange触发器。

Just add a function named on onSelectionChange and save the project.只需添加一个名为onSelectionChange的 function 并保存项目。 From now on, every time a different cell is selected, this function will execute.从现在开始,每次选择不同的单元格时,这个 function 都会执行。

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 .由于此问题,您可能需要在添加 function 后刷新电子表格。
  • 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.您可以使用相应的事件 object获取有关选择了哪个单元格的信息,该事件是您可以添加到 Apps 脚本触发器的参数,其中包含有关事件的信息。 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.虽然此 object 的属性尚未正式记录,但您可以通过记录JSON.stringify(e)来检查这些属性,如上面的示例所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM