问题
I am new to script and added this script which worked:
function sendEmailAlert() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cellValue = ss.getActiveSheet().getActiveRange().getA1Notation();
var getRow = ss.getActiveSheet().getActiveRange().getRow();
var sheetname = ss.getActiveSheet().getName();
var user = Session.getActiveUser().getEmail();
var Toemail = '....email address....';
var subject = 'New Entry -' + ss.getName();
var body = 'Your file has a new entry in - ' + sheetname + ' Updated by - ' + user + ' check file- ' + ss.getUrl();
if(Number(ss.getActiveCell().getValue()!=-1.23456789) && getRow ==3) {
MailApp.sendEmail(Toemail,subject, body);
}
};
However, as I would like to find out which specific cell was changed and the new value, the updated script fails to save so I cannot run it. I guess the mistake is in var body, can anyone help?
function sendEmailAlert() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cellValue = ss.getActiveSheet().getActiveRange().getA1Notation();
var getRow = ss.getActiveSheet().getActiveRange().getRow();
var sheetname = ss.getActiveSheet().getName();
var user = Session.getActiveUser().getEmail();
var Toemail = '...email address';
var subject = 'New Entry -' + ss.getName();
var body = 'Your file has a new entry in - ' + sheetname + ' Updated by - ' + user + ‘New Value in –‘ + cellValue + ‘= ‘ +ss.getActiveCell().getValue() +
' check file- ' + ss.getUrl();
if(Number(ss.getActiveCell().getValue()!=-1.23456789) && getRow ==3) {
MailApp.sendEmail(Toemail,subject, body);
}
};
回答1:
You are right regarding that there is a problem on the var body
code line: There are ‘
(curly quotes) instead of '
(straight quotes).
来源:https://stackoverflow.com/questions/56498642/notify-via-email-when-a-cell-is-updated-in-google-spreadsheet