当Google脚本中所有行的第8列的值与第3列的值匹配时,我正在尝试发送电子邮件。
function sendEmailNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lrow=ss.getLastRow()
var sheet = SpreadsheetApp.getActiveSheet();
for (var i = 2; i < lrow; i++)
{
if (sheet.getRange(i, 8).getValue() = sheet.getRange(i, 3).getValue())
var emailSubject = 'Value of ' + sheet.getRange(i, 1).getDisplayValue() + ' triggered, now pending your attention';
var emailBody = 'Person1 has approved the item on row ' + ' of spreadsheet "' + '".\n\n';
emailBody += 'To open the spreadsheet, click this link: ' + ss.getUrl() + '\n\n';
emailBody += '(this is an automatically sent message)';
MailApp.sendEmail("sdas22@gmail.com", emailSubject, emailBody);
; }}
答案 0 :(得分:0)
主要问题是IF语句
这是您的,它不起作用并且正在生成错误消息
if (sheet.getRange(i, 8).getValue() = sheet.getRange(i, 3).getValue())
这是我的作品
if ((sheet.getRange(i, 8).getValue()) == (sheet.getRange(i, 3).getValue())){
}
需要注意的几件事。
最后一行也有分号,看起来似乎不合适。
这是我的代码版本-运行
function sendEmailNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lrow=ss.getLastRow()
var sheet = SpreadsheetApp.getActiveSheet();
for (var i = 2; i < lrow; i++)
{
if ((sheet.getRange(i, 8).getValue()) == (sheet.getRange(i, 3).getValue())){
var emailSubject = 'Value of ' + sheet.getRange(i, 1).getDisplayValue() + ' triggered, now pending your attention';
var emailBody = 'Person1 has approved the item on row ' + ' of spreadsheet "' + '".\n\n';
emailBody += 'To open the spreadsheet, click this link: ' + ss.getUrl() + '\n\n';
emailBody += '(this is an automatically sent message)';
MailApp.sendEmail("sdas22@gmail.com", emailSubject, emailBody);
}
}
}