我想将下载功能添加到我的谷歌应用程序脚本中



在一些在线教程的帮助下,我编写了一个脚本,该脚本位于我的谷歌工作表中,它采用表单提交来基于我的模板生成我的信件。

一切都很好,但在保存了一个PDF文件后的最后一部分,我想添加到下载文件的选项中,并弹出一个问题。

"你想下载PDF吗;[是][否]

我很难理解如何实现它。

这是我没有下载选项的代码:

function jobFillGoogleDocFromForm(e) {
//e.values is an array of form values
var timestamp = e.values[0];
var jobType = e.values[1];
var jobTitle = e.values[2];
var companyName = e.values[3];

var now = new Date();
var day = now.getDate() +1;
var month = now.getMonth();
var year = now.getFullYear();
var todaysDate = day+'/'+month+'/'+ year

//determine which cover letter template to use based on the job type
if (jobType == '3D Art') {
var file = DriveApp.getFileById('1kENGdn8fALXPle28xHO2SCNsuHZiI1k4ckQhRlHJHoU');
} else {
var file = DriveApp.getFileById('1lSrtlBvzvMiL6YAdSSAUiHvHPVG_DAsopQIo3nr6924');
}

//We can make a copy of the template, name it, and optionally tell it what folder to live in
//file.makeCopy will return a Google Drive file object
var folder = DriveApp.getFolderById('1tS3CRWI2Vrh4RzS96n0I4lrktxLhCL6s')
var copy = file.makeCopy('AndreaMele_Cover_Letter' + '_' + jobTitle + ' - ' + companyName, folder); 

//Once we've got the new file created, we need to open it as a document by using its ID
var doc = DocumentApp.openById(copy.getId()); 

//Since everything we need to change is in the body, we need to get that
var body = doc.getBody(); 

//Then we call all of our replaceText methods
body.replaceText('{{todaysDate}}', todaysDate); 
body.replaceText('{{jobTitle}}', jobTitle);
body.replaceText('{{companyName}}', companyName);

//Save and close the document to persist our changes
doc.saveAndClose();

//Save out a copy as PDF
var docblob = doc.getBlob();
docblob.getAs('application/pdf').setName(doc.getName() + ".pdf");
folder.createFile(docblob);
}

正如我所看到的,您正在使用onFormSubmit触发器。此操作无法与用户交互。

您可以尝试向用户发送带有文件或下载链接的电子邮件。

相关内容

最新更新