用于在表单提交

时间:2016-05-18 19:32:44

标签: google-drive-api

非常感谢帮助我解决这个问题。我没有经验编码,所以如果你能提供帮助,请尽可能具体。

我按照一个教程来制作当有人完成表单时运行的东西。这个想法只是用表单响应替换模板doc中的变量。本教程使用它,以便在提交表单时,模板文档保存为PDF,然后通过电子邮件发送。

但是,我想将PDF下载到计算机上的驱动器中,而不是通过电子邮件发送。这甚至可能吗?

这是我的代码:

var docTemplate = "1JZnLGe5eqIIHe0R7YkN3fsoscoyeQ70k1a_aoYEXdzI";
var docName = "WV MR Request ";

function onFormSubmit(e) {

var facility_name = e.values[8];
var date = e.values[10];
var cli_first = e.values[2];
var cli_last = e.values[3];
var dob = e.values[4];
var last4 = e.values[5];
var date_range = e.values[6];
var adv_name = e.values[9];
var pronoun = e.values[7];
var email_address = Session.getActiveUser().getEmail();


var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName+' for '+cli_last +last4)
.getId();

var copyDoc = DocumentApp.openById(copyId);  

var copyBody = copyDoc.getActiveSection();  

copyBody.replaceText('keyFacilityName', facility_name);
copyBody.replaceText('keyDate', date);
copyBody.replaceText('keyCliFName', cli_first);
copyBody.replaceText('keyCliLName', cli_last);
copyBody.replaceText('keyDOB', dob);
copyBody.replaceText('keyLast4',last4);
copyBody.replaceText('keyDateRange', date_range);
copyBody.replaceText('keyAdvName', adv_name);
copyBody.replaceText('keyPronoun', pronoun);

copyDoc.saveAndClose();

var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

var subject = "WV Rates Letter" +cli_last +last4;
var body = "See attached letter for " + cli_first + cli_last + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});

DriveApp.getFileById(copyId).setTrashed(true);  

}

感谢您提供的任何帮助。我真的认为这将是一项简单的任务,但我在谷歌或这个网站上找不到任何东西。

0 个答案:

没有答案