我想每个工作日发送一封电子邮件。在一张纸上指定了地址列表。使用特定于事件的触发器时,将按原样发送电子邮件。但是,当我将其设置为时间驱动的触发器时,它无法正确执行。我收到有关我创建的numRows变量的以下错误:请首先选择一个活动工作表。 (第21行,文件“ sendEmails”)
// define how HTML object is being sent:
function convSheetAndEmail(rng, email, subj)
{
var HTML = SheetConverter.convertRange2html(rng);
MailApp.sendEmail(email, subj, '', {htmlBody : HTML});
}
// function 2:
function doGet()
{
var sh1 = SpreadsheetApp.getActive().getSheetByName('Dashboard')
var dataRange = sh1.getDataRange();
var sh2 = SpreadsheetApp.getActive().getSheetByName('control_panel')
var numRows = SpreadsheetApp.getActiveSpreadsheet('Sales/Ops Daily Report').getLastRow()-1;
var data = sh2.getRange(2,1,numRows,1).getValues()
// loop through the array with the mail addresses:
for (i in data) {
var row = data[i];
var emailAddress = row[0];
var subject = 'Sales/Ops Daily Report';
convSheetAndEmail(dataRange, emailAddress, subject);
}
}
// send email
function createTriggers() {
var days = [ScriptApp.WeekDay.MONDAY, ScriptApp.WeekDay.TUESDAY,
ScriptApp.WeekDay.WEDNESDAY, ScriptApp.WeekDay.THURSDAY,
ScriptApp.WeekDay.FRIDAY];
for (var i=0; i<days.length; i++) {
ScriptApp.newTrigger(doGet())
.timeBased().onWeekDay(days[i])
.atHour(14).create();
}
}
答案 0 :(得分:0)
方法ScriptApp.newTrigger()
应该使用 string 类型的参数,即函数名。您已将doGet()
调用用作参数。结果,触发器未正确安装。如果要触发此功能,则应编写:ScriptApp.newTrigger("doGet")
,依此类推。