为了使代码保持简单,并使用在线找到的模板工作,我遇到了一些错误。对于从具有各种信息的相当大的工作表发送一些收据,此代码是必需的。但是,在定义包含全名的列(如何定义var full_name)和包含电子邮件地址的列时,我需要一些帮助...在包含25行的工作表中,如何使此脚本起作用以逐一列出行并向每个人发送电子邮件?
感谢您的帮助
// Global variables
docTemplate = 'docid';
docName = 'Ricevuta 2018';
function sendDocument() {
// Full name and email address values come from the spreadsheet form
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheets()[0];
var full_name = dataSheet.getRange("A2:A3");
var email_address = dataSheet.getRange("P2:P3");
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName+' for '+full_name)
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,
copyBody.replaceText('keyFullName', full_name);
var todaysDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy");
copyBody.replaceText('keyTodaysDate', todaysDate);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "Ricevuta Itcca 2018-2019"
var body = "Testing body of email. Ciao" + full_name + "your receipt is attached."
MailApp.sendEmail(email_address, subject, body, pdf);
// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}