邮件与谷歌工作表合并



我为我的团队结果构建了一个谷歌表。我需要发出";KPI报告";每个员工的PDF格式。名称存储在(B2(上,我设置了一个Vlookup来链接员工电子邮件(D2(进行邮件合并。不知怎么的,它不起作用。它以低于错误消息的方式反弹。

错误
异常:无法发送电子邮件:没有收件人(匿名(@Trial.gs:37myFunction@试用版.gs:12

有人能为解决方案提供建议吗?https://docs.google.com/spreadsheets/d/15Egyl8q6pgxiCx4Tu0Rv6nRUADQGTEMxoIEvkPBE0D8/edit?usp=sharing

function myFunction() {
// 1. Retrieve values from "Sheet2".
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Individual KPI Report");
var values = sheet.getRange("A1:O29" + sheet.getLastRow()).getValues();
var template =  ss.getSheetByName("PDF");
var ssId = ss.getId();
var token = ScriptApp.getOAuthToken();
var filenameOfPdf = template.getSheetName();

// 2. Create sheets for converting to PDF data.
values.forEach(([v], i) => {
// 1. Copy the sheet `PDF` as the template.
var temp = template.copyTo(ss).setName("temp" + (i + 1));

// 2. Set the name at the cell "B2".
temp.getRange("B2").setValue(v);
SpreadsheetApp.flush();
var email = temp.getRange("D2").getValue();

// 3. Export the template sheet as the PDF data.
var subject = "Test Receipt ";
var body = "n Please see attached your current test receipt: ";
var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", ssId);
var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls / xlsx
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=true' // orientation, false for landscape
+ '&fitw=true&source=labnol' // fit to page width, false for actual size
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenumbers=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&gid='; // the sheet's Id
var response = UrlFetchApp.fetch(url + url_ext + temp.getSheetId(), {headers : {'Authorization' : 'Bearer ' + token}}).getBlob().setName(filenameOfPdf + ".pdf");

// 4. Send an email using the email corresponding to the name of "B2".
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {htmlBody : body,attachments : [response]});

// 5. Delete the template sheet.
ss.deleteSheet(temp);
});
}

我认为这是您所引用的工作表,因为电子邮件在个人KPI报告中

var email = sheet.getRange("D2").getValues();

相关内容

  • 没有找到相关文章

最新更新