如果Google表格中的单元格更改,则触发电子邮件 [英] Trigger email if cell changed in Google Sheet

查看:108
本文介绍了如果Google表格中的单元格更改,则触发电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表格,用于跟踪Google表格中的部门指标。我正在尝试在指标更改时将其发送给电子邮件。我使用counta(范围P2)来监视是否有新的度量标准进来,如果范围中的值发生变化,我想触发电子邮件。

I have a sheet where we track department metrics in Google Sheets. I am trying to get it to email when a metric changes. I am using counta (in range P2) to monitor if a new metric came in and I want to trigger an email if a value in the range changes.

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var value = ss.getSheetByName("EmailServices").getRange("P2").getValue().toString();
  var last = ScriptProperties.getProperty("last");

  if(value != last) 

  {
  ScriptProperties.setProperty("last",value);
  MailApp.sendEmail("dave@mydomain.com", "cell P2 changed",
    "new value: " + value + "\n\n" + ss.getUrl())
  }
}

我有趋势图表,最终希望收到电子邮件实际的趋势图会发生变化(输入一个新的月度值),但我想我会在跑步之前走路。 :)

I have trending charts and ultimately I'd like to email the actual trending chart is changed (a new monthly value is entered) but I thought I'd walk before I ran. :)

推荐答案

由于公式而更改的单元不符合触发onEdit函数的编辑的条件。
您应该监视源单元格(如果它们是手动编辑的),或者第二个选择是在每分钟运行一次触发器(或任何您喜欢的频率)下运行一个函数并发送电子邮件。
您写的函数看起来很好,可以在触发器下运行。

Cells that change because of a formula do not qualify as an 'edit' to trigger the onEdit function. You should either monitor the source cell(s) (if they are edited manually) or the second alternative is to have a function running under a trigger that runs every minute (or whatever frequency you like) and send out the email. The function you've written looks good to be run under a trigger.

这篇关于如果Google表格中的单元格更改,则触发电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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