我有一张隐藏的工作表,用于确定将通过电子邮件发送给谁。如果没有打开工作表,我现在的脚本将无法运行。是否可以运行该GAS而无需取消隐藏隐藏的工作表?
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(1,3);
var email = range.getValues();
var emailAddress = email[0][0];
var range = sheet.getRange(2,3); // Fetch the range of cells E1:E1
var CC = range.getValues();
var ccEmail = CC[0][0];
var range = sheet.getRange(3,3); // Fetch the range of cells E2:E2
var subject = range.getValues(); // Fetch value for subject line from above range
var EmailSubject = subject[0][0];
var range = sheet.getRange(5,4);
var message = range.getValues();
var messageBody = message[0][0];
MailApp.sendEmail({ to: emailAddress, cc: ccEmail , subject: EmailSubject, body: messageBody, });
}
答案 0 :(得分:0)
getSheetByName(名称)
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses");
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getSheetByName(String)