如何将附加单元格值事件/脚本附加到Google工作表 [英] how to attach onChange cell value event/script to google sheet

查看:160
本文介绍了如何将附加单元格值事件/脚本附加到Google工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将onChange方法附加到Google电子表格中的单元格。我想发送一封电子邮件给某人,一旦单元格中的值变得大于1000?

解决方案

在这个例子中,邮件如果单元格A1的值大于1000,并且您自己没有更改它的值,则发送它。



当然,您应该自定义电子邮件地址和单元格名称

  function sheetTracker(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cell = ss.getActiveCell()。getA1Notation(); $().b
$ b if(Session.getActiveUser()!='yourmail@gmail.com'&&
Number(ss.getActiveCell()。getValue())> 1000&& amp ; cell =='A1'){
MailApp.sendEmail('yourmail@gmail.com','电子表格中的修改',
'Cell'+ cell +'已被'+ Session修改.getActiveUser()+
' - new value ='+ ss.getActiveCell()。getValue()。toString());


$ / code>

您应该添加一个可安装的触发器 on edit (转到资源>当前工作表触发器>添加新触发器)并授权脚本。


How to attach an onChange method to a cell in google spreadsheet. I want to send an email to someone as soon a value in a cell becomes greater that 1000?

解决方案

In this example the mail is sent if cell A1 has a value >1000 and if you didn't change its value yourself.

You should of course customize the email address and the cell name to your needs.

function sheetTracker(){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var cell = ss.getActiveCell().getA1Notation();

    if(Session.getActiveUser()!='yourmail@gmail.com' &&
       Number(ss.getActiveCell().getValue())>1000 && cell=='A1'){
        MailApp.sendEmail('yourmail@gmail.com', 'Modification in the spreadsheet', 
       'Cell ' + cell + ' has been modified by '+ Session.getActiveUser() +
       ' - new value = ' + ss.getActiveCell().getValue().toString());
    } 
}

You should add an installable trigger on edit (go to resource>current sheet triggers>add new trigger) and authorize the script.

这篇关于如何将附加单元格值事件/脚本附加到Google工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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