一秒钟内多次调用 Google App Script onEdit 函数失败 [英] Failure of calling Google App Script onEdit function many times in a second

查看:33
本文介绍了一秒钟内多次调用 Google App Script onEdit 函数失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为 Google Apps 脚本的 onEdit 函数的奇怪行为而苦苦挣扎.

I have been struggling with a strange behavior of onEdit function of Google Apps Script.

据我所知,每次编辑单元格时都会触发这个 onEdit 事件.当我每 1 秒像一个单元格一样缓慢编辑一个单元格时,没有问题.肯定会触发所有事件.

To my understanding, this onEdit event is fired every time a cell is edited. It is no problem when I edit a cell slowly like one cell for every 1 second. All events are fired for sure.

但是,当我在一秒钟内快速编辑几个单元格时,其中一些单元格不会被触发.因此,即使我非常快速地编辑单元格,我也想确保触发 onEdit 事件.下面是我的代码,我遗漏了什么吗?

However, when I edit a few cells in a second very quickly, some of them aren't fired. So I want to make sure onEdit event is fired even when I edit cells very quickly. Below are my code, am I missing something?

我已经调试了一整天...请帮我解决这个问题.

I have been debugging for this whole day... Please help me out with this issue.

function onEdit(e){
  var as = SpreadsheetApp.getActiveSheet();
  var r = e.source.getActiveRange();
  var edditRow = r.getRow();
  console.log(edditRow);
  as.getRange(edditRow, 2).setValue('edited');
}

推荐答案

这是 onEdit 的一个已知限制.

This is a known limitation of onEdit.

从 Google 员工 Eric Koleda 的评论在新表格中一次只能排队两个 onEdit 触发事件

From a comment by Eric Koleda, a Googler, to Only two onEdit trigger events can be queued at a time in New Sheets

您必须假设 onEdit 触发器是尽力而为的,但可能无法捕获对电子表格所做的所有编辑.

You'll have to assume that onEdit triggers are best-effort, but may not catch all edits done to the spreadsheet.

这篇关于一秒钟内多次调用 Google App Script onEdit 函数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆