如何将另一个列比较添加到现有比较中?

时间:2019-05-16 16:24:03

标签: google-apps-script

如何添加与A列中的值的比较,例如:

如果A列上的值为test1,我将发送电子邮件至test1@mail.com,
如果值是test2,请发送电子邮件到tes2@mail.com等。

function sendEmailAlert() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var data = ss.getActiveSheet().getActiveCell().getA1Notation();
    var sheetname = ss.getActiveSheet().getName();
    var getColumn = ss.getActiveSheet().getActiveRange().getColumn();
    var user = Session.getActiveUser().getEmail();
    var Toemail = 'randomemail@mail.com';
    var subject = 'New Entry -' + ss.getName();
    var body = 'random text';

    if(Number(ss.getActiveCell().getValue()!=-1.23456789) && getColumn ==2) {

         MailApp.sendEmail(Toemail,subject,body); 
    }
};

If I change value in column B, and the value in column A is `test1` I'll send email to test1@mail.com.  If I change column B and value in column A is `test2` I'll send email to test2mail.com

1 个答案:

答案 0 :(得分:0)

您可以使用group = specific value对象上可用的getCell(row, column)函数来获取当前活动单元格左侧的单元格内容(假设第一列是电子邮件地址,第二列是电子邮件地址)列包含要修改的单元格)。以下代码段选择了电子邮件的目标电子邮件地址,将更改后的单元格的值作为正文发送给正文:

Range

重要的一行是定义function sendEmail() { // Spreadsheet info var ss = SpreadsheetApp.getActiveSpreadsheet(); // get all sheets var sheet = ss.getActiveSheet(); // get current sheet var data = sheet.getDataRange(); // get all data in the active sheet var sheetname = sheet.getName(); // Current cell info var cell = sheet.getActiveCell(); var currColumn = cell.getColumn(); var currRow = cell.getRow(); // Email setup var user = Session.getActiveUser().getEmail(); var subject = 'New Entry - ' + ss.getName(); // Do I send an email? if(Number(ss.getActiveCell().getValue() != -1.23456789) && currColumn == 2) { var toEmail = String(data.getCell(currRow, currColumn - 1).getValue()); var body = data.getCell(currRow, currColumn).getValue(); MailApp.sendEmail(toEmail, subject, body); } }; 的行,它要求toEmail