我一直在努力让这个appScript在我的Google表格中发挥作用。目前它已经被卡住了#34;在MailApp.sendEmail行上,特别是在emailAddress上。它给了我这个错误消息"无效的电子邮件:未定义"。我将大部分脚本都放在Sending Emails from a Spreadsheet Tutorial上。所以我不太确定它可能出错的地方。
非常感谢任何帮助!
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheetByName("Candidates Ready for Offer");
var startRow = 2; // First row of data to process
var numRows = ss.getSheetByName("Candidates Ready for Offer").getLastRow()-1;
// Fetch recent additions
var dataRange = ss.getSheetByName("Candidates Ready for Offer").getRange(startRow, 3)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[5];
var message = "row[1]" + "row [2]" + "at" + "row[4]" + "is ready for an offer!"
var subject = "Candidate is Ready for Offer";
MailApp.sendEmail(emailAddress, subject, message);
}
}
答案 0 :(得分:1)
感谢您分享您的表格。实际上有很多原因导致它不起作用,我会尝试解释。无论如何,共享工作表上的脚本现在将按您的需要运行。这是它的样子:
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheetByName("Candidates Ready for Offer");
var startRow = 4; // First row of data to process
var numRows = sh0.getLastRow()-startRow+1;
// Fetch recent additions
var dataRange = sh0.getRange(startRow,1,numRows,6);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
Logger.log(data);
for (i in data) {
var row = data[i];
var emailAddress = row[3];
Logger.log(emailAddress);
var message = "row[1]" + "row [2]" + "at" + "row[4]" + "is ready for an offer!"
var subject = "Candidate is Ready for Offer";
MailApp.sendEmail(emailAddress, subject, message);
}
}
我希望这有助于/有意义。
奥利
答案 1 :(得分:-1)
问题是你的var dataRange。目前,您的代码只获得一个单元格(startrow,3)的范围,而不是数组。
用getDataRange()替换.getRange(startrow,3)可以解决你的问题。