Send E-mail with Excel file converted from Spreadsheet
This sample script sends an e-mail with an Excel file exported from Spreadsheet as an attachment file.
function excelSender() {
var sheetID = [Sheet ID];
var xlsxName = [Excel file name];
var params = {
"headers" : {Authorization: "Bearer [Retrieved AccessToken]"},
"muteHttpExceptions" : true
};
var dUrl = "https://www.googleapis.com/drive/v3/files/" + sheetID + "/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
var xlsxlFile = UrlFetchApp.fetch(dUrl, params).getBlob().setName(xlsxName);
MailApp.sendEmail({
to: [Mail address],
subject: "sample subject",
body: "sample body",
attachments: [xlsxlFile]
});
}