问题描述
我在下面设置了Google脚本的各个部分,以根据模板以及从Google表单添加的变量来生成新文档。
然后将新文档转换为PDF并作为附件通过电子邮件发送。
我现在还想做的是包括指向Google文档本身的超链接。
我可以看到DocumentApp.openByUrl是可能的功能,但不知道如何应用。
autoFillGoogleDocFromForm
//e.values is an array of form values
var Timestamp = e.values[0];
var Channel = e.values[1];
var Name = e.values[2];;
var file = DriveApp.getFileById('FILEID');
var folder = createChannelFolder(); // 1st modification point
var copy = file.makeCopy(Channel + ',' + Name,folder);
var newId = copy.getId();
var doc = DocumentApp.openById(newId);
var body = doc.getBody();
body.replaceText('{{Timestamp}}',Timestamp);
body.replaceText('{{Channel}}',Channel);
body.replaceText('{{Name}}',Name);
doc.saveAndClose();
}
发送html电子邮件
//Setup embedded image.
var imgID = "IMAGEID"
var imageURL = "https://drive.google.com/uc?id="+imgID;
var imageBlob = UrlFetchApp
.fetch(imageURL)
.getBlob()
.setName("imageblob");
var body = HtmlService.createTemplateFromFile("html");
body.Name = Name;
body.Channel = Channel;
var Blob = doc.getBlob().getAs('application/pdf');
var Email = Email;
var subject = 'Submitted';
var values = e.values;
GmailApp.sendEmail(Email,subject,body,{htmlBody: body.evaluate().getContent(),inlineImages:
{
imageblob: imageBlob},attachments: [{
fileName: Channel + ".pdf",content: Blob.getBytes(),mimeType: "application/pdf"}]
});
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)