Hi I'm using this script to create and email a sheet from google sheet that works great but i would also like to have the script attach all the file that are in a specific folder from google drive and then email my google sheet and the files from the folder in one email.
'''
function Test() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var spreadsheet = spreadsheetId ? SpreadsheetApp.openById(spreadsheetId)
:SpreadsheetApp.getActiveSpreadsheet();
var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
var body = 'test'
var email = Session.getActiveUser().getEmail();
var token = ScriptApp.getOAuthToken();
var ssID = spreadsheetId;
var url = "https://docs.google.com/spreadsheets/d/"+ssID+"/export"+
"?format=pdf&"+
'&portrait=true' + //orientation, false for landscape
'&scale=4' +
'&top_margin=0.25' + //All four margins must be set!
'&bottom_margin=0.25' + //All four margins must be set!
'&left_margin=0.05' + //All four margins must be set!
'&right_margin=0.05' + //All four margins must be set!
'&horizontal_alignment=CENTER'; //LEFT/CENTER/RIGHT
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + token
}
});
var att = response.getBlob().setName( 'Test.PDF')
var files = DriveApp.getFolderById('1GW6_ofWqztakjKJ9WWtxo7dhnPX0js').getFiles();
var attachements = [];
while (files.hasNext()) {
var file = files.next();
attachements.push(file.getAs(MimeType.PDF));
}
GmailApp.sendEmail(email, " Subject " , body, {
attachments: attachements
});
}
''' when I use " attachments: attachements " I get all the files from the folder as attachment and when I use " attachments: att " I get my google sheet as attachment but i cant seem to figure out how to get my google sheet plus all the files from the folder on the same email
Thanks for you help