简体   繁体   English

从单元格值Google工作表发送电子邮件,以及电子邮件中的其他列

[英]Send email from cell value google sheet, with other columns in email

Apologises as I know this has been asked a few times, which I have learnt from other questions, however I'm still stuck and not sure how to continue. 很抱歉,我已经问过几次了,这是我从其他问题中学到的,但是我仍然很困惑,不确定如何继续。

I'm trying to make a google script to send an email notification to more then one person, based on a cell change, also sending in the email multiple cell values in the same row? 我正在尝试制作一个Google脚本,根据单元格更改将电子邮件通知发送给一个以上的人,同时在同一行中向电子邮件发送多个单元格值?

eg If Column 'C' changes, can I send an email with data from Column 'A' and 'B' in the same Row of the change in column 'C'? 例如,如果“ C”列发生更改,是否可以发送电子邮件,其中包含“ C”列更改的同一行中“ A”列和“ B”列的数据?

This is the script I've been trying to play around with but not sure how to add multiple e-mails, and values from two more cells. 这是我一直在尝试使用的脚本,但不确定如何添加多封电子邮件以及另外两个单元格中的值。

function sendNotifications() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var row = sheet.getActiveRange().getRow();
var cellvalue = ss.getActiveCell().getValue().toString();
var recipients = email@domain.com";
var message = '';
var cellA = ''
if(cell.indexOf('B')!=-1){ 
message = sheet.getRange('A'+ sheet.getActiveCell().getRowIndex()).getValue()
}
var subject = 'Update to '+sheet.getName();
var body = + cellvalue + '». For message: «' + message + '»';
MailApp.sendEmail(recipients, subject, body);
};

The code below checks if the edited cell was in column C and, if the condition is met, gets the values for columns A and B from the edited row. 下面的代码检查是否已编辑的单元格位于C列中,如果满足条件,则从已编辑的行中获取A列和B列的值。 In Google Apps Script, onEdit() is the built-in function that fires automatically when you make changes in your spreadsheet. 在Google Apps脚本中,onEdit()是内置函数,当您在电子表格中进行更改时会自动触发。 The 'e' parameter represents the event object that you can inspect to get more details about the context in which the event occurred “ e”参数表示事件对象,您可以检查该事件对象以获取有关事件发生的上下文的更多详细信息

function onEdit(e){

  var editRange = e.range; // e is the event object generated by the Edit event
  var editRow = editRange.getRow();   // get row and column for the edited cell
  var editCol = editRange.getColumn();


  var sheet = SpreadsheetApp.getActiveSpreadsheet()
                            .getSheetByName("Sheet1"); // put your sheet name between the brackets

  if (editCol == 3) {   // checking if the edited cell was in column C

      var range = sheet.getRange(editRow, 1, 1, editCol - 1); // Take 1st cell in the edited row and make it span 1 row and 2 columns
      var values = range.getValues(); // get values array for the range
      Logger.log(values);

  }

}

The resulting variable ('values') is an array, so you must loop through it to get string values. 结果变量(“值”)是一个数组,因此必须遍历它才能获取字符串值。 As for the emails, you could store multiple emails in a cell, separated by comma. 至于电子邮件,您可以将多个电子邮件存储在一个单元格中,并以逗号分隔。 Calling split() method on a string will get you an array of values (emails) that you can then pass to the sendEmail method as the first parameter. 在字符串上调用split()方法将获得一个值(电子邮件)数组,然后可以将其作为第一个参数传递给sendEmail方法。

  var cellValue = "email@example.com,anotheremail@example.com,yetanotheremail@example.com";
  var recipients = cellValue.split(",");  
  MailApp.sendEmail(recipients, "From google-apps-script", "hello from google apps script")

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

相关问题 如何使用gs从谷歌表格发送带有格式化表格的电子邮件? - How to send an email with a formatted table from google sheet using gs? 如果单元格值匹配,则发送 email - Send email if a cell value matches 发送来自多个偏移行的更改的单元格值的电子邮件 - Send email from changed cell value from multiple offset rows VBA当单元格等于另一个工作表中的单元格时发送电子邮件 - VBA Send email when cell equals cell in another sheet VBA-将工作表中的单元格复制到Outlook电子邮件中 - VBA - Copy Cell from Sheet into Outlook email 通过 email 发送表格 - Send sheet via email 库存电子表格 - 当单元格值 =“过期”时发送电子邮件并使用表格中的信息填充电子邮件 - Inventory Spreadsheet - Send email when cell value = "Expired" and populate email with info from table VBA 在单元格值更改时发送电子邮件 - VBA Send Email When Cell Value Changes 如果Google工作表中的指定列发生更改,则发送电子邮件通知 - Sent email notification if a change happens on specified columns on a google sheet 如果其他两列的值匹配,则将值从一张工作表中的单元格复制到另一张工作表中最后使用的列中的单元格 - Copy value from a cell in one sheet to a cell in the last used Column in another sheet, if values in two other Columns' values match
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM