2016-11-17 131 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行,文件「代碼」) –