google-apps-script - 检测用户在谷歌电子表格中插入行或列并在脚本中使用react

标签 google-apps-script google-sheets google-apps-script-addon

在 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:

  1. From the script editor, choose Edit > Current project's triggers.
  2. Click the link that says: No triggers set up. Click here to add one now.
  3. Under Run, select the name of function you want to trigger.
  4. Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).
  5. 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).
  6. Optionally, click Notifications to configure how and when you will be contacted by email if your triggered function fails.
  7. Click Save.


在第 4 步中,您将选择 来自电子表格 在第 5 步中,您将选择 更改中 .这应该有你正在寻找的效果。如果您尝试在要分发给用户的附加组件中使用它,还可以选择以编程方式添加触发器和请求授权。两者都在 Installable Triggers 中有详细说明文档。

关于google-apps-script - 检测用户在谷歌电子表格中插入行或列并在脚本中使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15232405/

相关文章:

javascript - 如何在 HTML 页面中的每个链接前面添加一个字符串?

mysql - 如何跳过 autoIncrement 列以使用 JDBC Google Apps 脚本在 mySQL 数据库上写入数据

google-apps-script - Google Sheets 脚本和 Google Sheets API 有什么区别?

validation - 动态创建的下拉验证列表

google-apps-script - 使用 Google Sheet Add-on 时 Stackdriver 中 "Script delayed (xx min) waiting for quota"的含义

google-apps-script - 具有有限身份验证的附加组件无法打开侧边栏

google-apps-script - 如何计算Google表格文档中的公式数量?

arrays - 仅提取谷歌表格中每个单元格的第一行

javascript - Google Apps 脚本 - 将带有样式的 HTML 转换为 PDF 并附加到电子邮件 - 从 HTML 创建 PDF Blob