简体   繁体   English

如何启动工作表中仅一个特定单元格的Google脚本函数onEdit?

[英]How to fire a Google Script function onEdit of just one particular cell in a sheet?

I have a Google Sheet with a custom script containing a function which I want to fire ONLY when cell A1 is edited. 我有一个带有自定义脚本的Google表格,其中包含一个仅在编辑单元格A1时才要触发的功能。 I've got it so that my function runs every time anything in the sheet is edited, but I want it to run only when cell A1 changes (and, ideally, only when it changes to something other than empty or null). 我已经做到了,以便每次编辑工作表中的任何内容时函数都可以运行,但是我希望它仅在单元格A1发生更改时才运行(理想情况下,仅当它更改为非空或null时才运行)。 Is there a way to do this? 有没有办法做到这一点? This is what I've got at the moment: 这是我目前所拥有的:

function inventoryAdd() {
    // ...custom function stuff... 
}

function onEdit(event) {
    inventoryAdd();
}

there are many ways to do it like inspecting the changed range in the "e" parameter. 有很多方法可以执行此操作,例如检查“ e”参数中更改的范围。 the easiest way is to simply remember (in script properties service) the last value you saw of that cell (from the previous onEdit call) and compare it with the current value. 最简单的方法是(在脚本属性服务中)简单地记住(在上一个onEdit调用中)该单元格看到的最后一个值,并将其与当前值进行比较。

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

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