2016-11-17 126 views
0

通过电子邮件通知要更改的特定列中的值时,如果电子表格的AQ列中的任何单元格发生更改,我需要通过电子邮件通知。我写了一个不工作的公式。使用脚本编辑器

电子表格和公式的图像如下。

enter image description here

function onEdit(e){ 
    //To get email notification if any changes to the perticular cells 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName("Notificações"); 
    var cell = ss.getActiveCell().getA1Notation(); 
    var row = sheet.getActiveRange().getRow(); 
    var cellvalue = ss.getActiveCell().getValue().toString(); 
    var recipients = "[email protected]"; 
    var message = ''; 
    if(cell.indexOf('AQ')!=-1) { // means that if you edit column AQ 
    message = sheet.getRange('AQ'+ 
     sheet.getActiveCell().getRowIndex()).getValue() 
    } 
} 
var subject ='Notificação de Alta Prioridade ' 
var body =' Você acaba de receber uma notificação de alta prioridade. Acesse sua planilha de notificações para que possa elaborar uma tratativa' 
Logger.log(body); 
//MailApp.sendEmail("[email protected]","Notificação de alta prioridade","Você acaba de receber uma notificação de alto risco, acesse sua planilha de notificações para que possa elaborar uma tratativa; 
+0

请转换代码的文本,并将其放置在你的问题。图像令人不悦。 – axlj

+0

另外一些谷歌搜索产生这样的:http://www.makeuseof.com/tag/send-emails-excel-vba/ – axlj

回答

0

您的括号是在错误的地点,这里是正确的代码:

function onEdit(){ 
    //To get email notification if any changes to the perticular cells 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName("Notificações"); 
    var cell = ss.getActiveCell().getA1Notation(); 
    var row = sheet.getActiveRange().getRow(); 
    var cellvalue = ss.getActiveCell().getValue().toString(); 
    var recipients = "[email protected]"; 
    var message = ''; 
    if(cell.indexOf('AQ')!=-1) {// means that if you edit column AQ 
    message = sheet.getRange('AQ'+ sheet.getActiveCell().getRowIndex()).getValue() 
    var subject ='Notificação de Alta Prioridade ' 
    var body =' Você acaba de receber uma notificação de alta prioridade. Acesse sua planilha de notificações para que possa elaborar uma tratativa' 
    Logger.log(body); 
    MailApp.sendEmail(recipients,subject,body); 
    } 
} 
+0

我真的apreciate你的帮助,但是当我尝试运行时出现:TypeError:“getActiveRange”方法的null不能被调用。 (第6行,文件“代码”)忽略。我真的是初学者在Java脚本,如果你可以再帮我... [email protected] 的Sair Notificação ArquivoEditarVisualizarExecutarPublicarRecursosAjuda onEdit –

+0

你需要确保你有一个名为“Notificações”表。 – utphx

+0

嘿,在第一次代码工作正常,但现在它弹出首先选择一个活动页面。 (第5行,文件“代码”) –