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

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

问题描述

如何将 onChange 方法附加到 Google 电子表格中的单元格.我想在单元格中的值大于 1000 时立即向某人发送电子邮件?

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?

推荐答案

在此示例中,如果单元格 A1 的值 >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());
    } 
}

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

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

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

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