在 Google Apps Script 中,基本工具之一是电子表格中的 onEdit 触发器,它使我们能够检测用户何时编辑单元格并对其使用react。
当用户插入一行或一列时怎么样?有没有办法检测到?
这会触发 onEdit 吗?如果是这样,我想在 ScriptDb 中维护一个行数或列数,然后每次检查都可以,但会非常耗时,因为 getMaxRows() 已经很慢了,而与 ScriptDb 联系就像好。
你怎么认为 ?
最佳答案
Google 添加了一个“On Change”事件,用于检测行/列插入/删除以及其他类型的更改,您可以看到这些类型的更改 here低于 changeType
的允许值.以下是来自 here 的说明详细说明如何向您的项目添加触发器,以便您可以在“更改时”事件发生时调用您的函数。
To manually create an installable trigger through a dialog in the script editor, follow these steps:
- From the script editor, choose Edit > Current project's triggers.
- Click the link that says: No triggers set up. Click here to add one now.
- Under Run, select the name of function you want to trigger.
- Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).
- Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).
- Optionally, click Notifications to configure how and when you will be contacted by email if your triggered function fails.
- Click Save.
在第 4 步中,您将选择 来自电子表格 在第 5 步中,您将选择 更改中 .这应该有你正在寻找的效果。如果您尝试在要分发给用户的附加组件中使用它,还可以选择以编程方式添加触发器和请求授权。两者都在 Installable Triggers 中有详细说明文档。
关于google-apps-script - 检测用户在谷歌电子表格中插入行或列并在脚本中使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15232405/