2016-11-30 25 views
0

我的代碼生成此錯誤:JavaScript錯誤在電子表格

`ReferenceError: "cell" is not defined. (Line 7, file "Code")` 

我希望當「AR」列的任何細胞編輯通知。 picture of spreadsheet

我的代碼:

function onEdit() { //To get email notification if any changes to the particular cells 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName("Notificações"); 
    var cell = ss.getActiveCell().getA1Notation(); 
    var cellvalue = ss.getActiveCell().getValue().toString(); 
    var recipients = "[email protected]"; 
    var message = ''; 
    if(cell.indexOf('AQ') != -1) {// means that if you edit column AQ 
    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

,我正在使用的代碼:功能onEdit(){// 要獲得電子郵件通知,如果到所述特定的細胞的任何變化 變種SS = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(「Notificações」); var cell = ss.getActiveCell()。getA1Notation(); var cellvalue = ss.getActiveCell()。getValue()。toString(); var recipients =「[email protected]」; –

+0

var message =''; if(cell.indexOf('AQ')!= - 1){//表示如果您編輯列AQ var subject ='Notificaçãode Alta Prioridade' var body ='Vocêacaba de receber umanotificaçãode alta prioridade 。 Acesse sua planilha denotificaçõespara que possa elaborar uma tratativa' Logger.log(body);MailApp.sendEmail(recipients,subject,body); } } –

+0

我已經爲'AR'更改'AQ',但仍然出現: ReferenceError:未定義「單元格」。 (第7行,「代碼」文件)解僱 –

回答

0

我複製你的代碼,我的牀單之一。 我唯一的錯誤信息是

Missing ; before statement. (line 10, file "Copy of Code").

改變Prioridade「變種到Prioridade 後;'var並在tratativa'Logger之間添加另一個分號,我成功通過更改獲得電子郵件通知。

完整代碼:

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 cellvalue = ss.getActiveCell().getValue().toString() ; 
    var recipients = "[email protected]" 
    var message  = ''; 

    if(cell.indexOf('AR')!=-1) {// means that if you edit column AQ 
     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); 
    } 
}