我正在制作一个脚本,该脚本获取电子表格,将其转换为pdf文件,然后将此pdf保存在文件夹中,并通过电子邮件作为附件发送。但是,我使用的唯一功能是通过电子邮件发送附件,但是当我打开电子邮件时,它会在电子邮件上显示消息“ [object Object]”。有人能帮我吗?
function SendEmail(){
var sheetMail = SpreadsheetApp.getActiveSpreadsheet();
var ecrvc = sheetMail.getSheetByName('List');
var planilha = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('List')
var
var subject = "Subject"
var message = "message"
var email = "person1@gmail.com"
//var ecrvc = "Sheet1";
var folderID = "folderId"; // Folder id to save in a folder.
var pdfName = "YourSpreadsheet of "+week+"-20";
var sourceSpreadsheet = SpreadsheetApp.getActive();
var sourceSheet = sourceSpreadsheet.getSheetByName(ecrvc);
var folder = DriveApp.getFolderById(folderID);
//Copy whole spreadsheet
var destSpreadsheet = SpreadsheetApp.open(DriveApp.getFileById(sourceSpreadsheet.getId()).makeCopy("tmp_convert_to_pdf", folder))
var destSheet = destSpreadsheet.getSheets()[0];
//save to pdf
var theBlob = destSpreadsheet.getBlob().getAs('application/pdf').setName(pdfName);
var newFile = folder.createFile(theBlob);
//Delete the temporary sheet
DriveApp.getFileById(destSpreadsheet.getId()).setTrashed(true);
//Send the email with attachments
var arquivo = theBlob;
DriveApp.getFileById(theBlob);
MailApp.sendEmail(email, subject,{
// htmlBody: message + "", noReply:true,{
attachments: [file.getAs.file(arquivo.PDF)],
name: pdfName
});
}
答案 0 :(得分:3)
有几个问题
file
未声明,并且getAs
语法错误。
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});