这里的第一个问题,但过去几天我一直在搜索这个网站。我可以通过基于谷歌教程的脚本看到这个令人难以置信的新功能!
我的任务是设置一个带有定时触发器的脚本,根据添加到Google电子表格中多个工作表的信息发送电子邮件。我试图在一个Google电子表格中使用3张不同的工作表。
非常感谢,这个网站已经有了丰富的知识。
编辑:谢谢大家,我已经进一步了解。我可以向所有工作表发送电子邮件,但只有我引用的最后一张工作表批量发送电子邮件,“支持人员”。前两张表一次只发送一封电子邮件“管理员”和“教师”。希望这有一个简单的原因。我确信我的剧本很丑陋而且多余。var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var startRow = 2;
var numRows = 1000;
var sheet = ss.getSheetByName ('Administrators')
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1];
var message = row[28];
var emailSent = row[29];
if (emailSent != EMAIL_SENT) {
var subject = "Tuition Reimbursement Status";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
var sheet = ss.getSheetByName ('Teachers')
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1];
var message = row[28];
var emailSent = row[29];
if (emailSent != EMAIL_SENT) {
var subject = "Tuition Reimbursement Status";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
var sheet = ss.getSheetByName ('Support Staff')
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1];
var message = row[28];
var emailSent = row[29];
if (emailSent != EMAIL_SENT) {
var subject = "Tuition Reimbursement Status";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
}
}
}
}
答案 0 :(得分:0)
我还没有测试过这个。但理想情况下,您需要为工作表对象中的每个工作表调用sendEmails2()方法。
var EMAIL_SENT = "EMAIL_SENT";
var sheets = ['Administrator', 'Teachers', 'Support Staff'];
function sendEmails2(sheetName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
var startRow = 2;
var numRows = 1000;
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[1];
var message = row[28];
var emailSent = row[29];
if (emailSent != EMAIL_SENT) {
var subject = "Tuition Reimbursement Status";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
for(i=0; i<sheets.length;i++){
sendEmails2(sheets[i]);
}