我想附加一个特定的谷歌表标签是包含在电子表格与多个标签在电子邮件中使用应用程序脚本。附件应为excel文件,即。xls格式。
请帮助。
解决方案:
您可以使用以下代码实现此任务。
请根据实际情况更改前两行内容。代码:
function sendSheetTab() {
var sheetName = 'sheet1'
var destinationEmail = 'some@email.com'
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName(sheetName)
var params = ss.getId() + "/export?gid=" + sheet.getSheetId() + "&format=xlsx"
var url = "https://docs.google.com/spreadsheets/d/" + params
var options = {
"method": "GET",
"headers": {
"authorization": "Bearer " + ScriptApp.getOAuthToken()
}
};
var result = UrlFetchApp.fetch(url , options)
var contents = result.getContent()
var subject = 'Sending sheet: ' + sheetName
var body = 'With Apps Script'
GmailApp.sendEmail(destinationEmail, subject, body, {attachments:[{fileName: sheetName + ".xls", content:contents, mimeType:"application//xls"}]})
}
参考:- SpreadsheetApp
- UrlFetchApp.fetch
- GmailApp.sendEmail