【发布时间】:2021-04-21 16:05:04
【问题描述】:
您好,我一直在尝试编写我的第一个脚本,以仅从我的一个 Google 文档中发送一张工作表,但每次我最终都发送了所有工作表。该文档每天都有一个主页,其中我有电子邮件列表,然后是 7 张称为星期一、星期二等的表格
这是我使用的代码 - 你能帮忙吗?
function emailActivesheetAsPDF() {
DocumentApp.getActiveDocument();
DriveApp.getFiles();
const ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1_3VpJaFliJVYt1JL3cLSKw2ftsmsLeDjznHJ66-wq9w/edit");
const value = ss.getSheetByName("Daily").getRange("B5").getValue();
const email = value.toString();
const subject = 'Yesterday Handover';
const body = "Please find attached yesterday handover";
const url = 'https://docs.google.com/spreadsheets/d/1_3VpJaFliJVYt1JL3cLSKw2ftsmsLeDjznHJ66-wq9w/export?';
const exportOptions =
'exportFormat=pdf&format=pdf'
'&size=legal'
'&portrait=true'
'&fitw=false'
'&sheetnames=false&printtitle=false'
'&pagenumbers=false&gridlines=false'
'&fzr=false'
'&gid=1263775066';
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
attachments: [{
fileName: "Handover" + ".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
}
【问题讨论】:
标签: javascript email pdf google-apps-script google-sheets