在应用程序脚本中如何自动化一系列工作表应该是快照并通过电子邮件或任何其他社交应用程序发送 我有一张每天都会更改数据的工作表,我需要每天将那份数据快照发送给我的老板我该如何自动化,请帮助我
我想在应用程序脚本中实现这种自动化
您可以使用 MailApp 类。在此处查看 SendEmail() 的文档:
https://developers.google.com/apps-script/reference/mail/mail-app#sendemailmessage
这是一个您可以使用的示例脚本:
function sendData() {
var emailAddress = '[email protected]';
var subject = 'Data';
var message = 'Here is the data';
var attachmentName = 'data.xlsx';
var fileId = "insert your spreadsheet ID here";
var data = UrlFetchApp.fetch(
"https://docs.google.com/feeds/download/spreadsheets/Export?key=" + fileId + "&exportFormat=xlsx",
{
"headers": {Authorization: "Bearer " + ScriptApp.getOAuthToken()},
"muteHttpExceptions": true
}
).getBlob().setName(attachmentName);
var optAdvancedArgs = {name: attachmentName, attachments: [data] };
GmailApp.sendEmail(emailAddress, subject, message, optAdvancedArgs);
}