使用Google脚本将PDF附加到电子邮件中

时间:2017-12-05 17:08:18

标签: forms pdf google-apps-script google-sheets

我正在尝试将Google脚本发送PDF作为电子邮件的附件。我有一个doc模板,它使用复制然后填写的表单数据。该代码有效,但程序仍然将模板作为pdf而不是填写的副本发送。谁能帮我这个? 以下是我的一些代码:

newDoc = autoWriteNewIEPForm(templateDocId, newDocName, fieldArray, NewEntryArray, submitTeacherName);
newDocId = newDoc.getId();
newDocURL = newDoc.getUrl();
var sender = newEntryArray[0][3];
var subSubject = newDocName;
var subEmailBody = "Thank you for submitting this information.  This receipt confirms that we have received your information." + "<br><br>";
var file = DriveApp.getFileById(newDocId).getAs(MimeType.PDF);
MailApp.sendEmail(sender, subSubject, "", {cc:emailCC, htmlBody:subEmailBody, attachments:[file], name: newDocName});

1 个答案:

答案 0 :(得分:0)

您的代码的最后一行是正确附加newDoc作为附件。第一行让我感到困惑; autoWriteNewIEPForm不是Google脚本功能,我不知道您从哪里获取它,或者您是否正确使用它。我的猜测是你错误地使用它,或者由于某种原因它没有编辑newDoc中的任何文本,所以你有一个技术上是模板副本但看起来完全相同的文档。

Body class of the Google Scripts DocumentApp中,您可以找到许多方法来编辑文档正文中的文本。我建议你改用其中一个。