首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不发送电子邮件将Google窗体数据转换为PDF的简短脚本

不发送电子邮件将Google窗体数据转换为PDF的简短脚本
EN

Stack Overflow用户
提问于 2015-11-02 20:32:38
回答 2查看 1.6K关注 0票数 1

我正在与本教程合作,试图将从谷歌表单中提交的数据转换为PDF格式。问题是,我没有收到任何电子邮件。电子表格更新得很好,但没有电子邮件。

我对编码很满意,但我从未使用过Google脚本。似乎有些代码已经过时了。我通过查找和替换将"DocsList“改为"DriveApp”,并将"MailApp“改为gmail应用程序。

在等待for事件时,我不知道从哪里开始,甚至不知道如何使用调试器。任何建议都会得到极大的认可。谢谢。

这是我的代码:

代码语言:javascript
运行
复制
//:שְׁמַע יִשְׂרָאֵל יהוה אֱלֹהֵינוּ יהוה אֶחָד
//Christian Shields (ChristianShields@gmail.com)
//Job Application Google Form to PDF converter
//11/2/15

//get the document from Google Docs and name it
var docTemplate = "1wgkvO-1xrVGJkD-JJ2FMRbQj_bfGu7qFAa6pTEJ61Cw";
var docName = "NewCherryHillJobApplication";

function onFormSubmit(e){
  //set the email address where the finished document will go.
  var docs_email = "ChristianShields@gmail.com";

  //get information from the newly submited form
  var full_name = e.values[2];
  var age = e.values[3];
  var address = e.values[4];
  var phone = e.values[5];
  var alt_phone = e.values[6];
  var email

  //Get the document template and copy it as a new temp document. Save the document ID's
  var copyId = DriveApp.getFileById(docTemplate)
  .makeCopy(docName+' for '+full_name)
  .getId();

  //open the temp document
  var copyDoc = DocumentApp.openById(copyId);
  //go to the temp documents body
  var copyBody = copyDoc.getActiveSection();

  //replace the text in the temp document
  copyBody.replaceText('keyFullName', full_name);
  copyBody.replaceText('keyAge', age);
  copyBody.replaceText('keyAddress', address);
  copyBody.replaceText('keyPhone', phone);
  copyBody.replaceText('keyAltPhone', alt_phone);
  copyBody.replaceText('keyEmail', email);

  //save and close the temp document
  copyDoc.saveAndClose();

  //convert the temp document to pdf
  var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

  //Attach PDF and send the email
  var subject = "New Doc's Job Application Submited Online";
  var body = "A new job application has been recieved from " + full_name + ". Primary phone number for this applicant is: " + phone + "";
  GmailApp.sendEmail(docs_email, subject, body, {htmlBody: body, attachments: pdf});

  // Delete temp file
  DriveApp.getFileById(copyId).setTrashed(true); 
} //End of dunction "onFormSubmit
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-03 21:58:39

这一行代码:

代码语言:javascript
运行
复制
var copyBody = copyDoc.getActiveSection();

使用名为getActiveSection()的方法。该方法不在文档中,也不在自动完成列表中。它并不存在。奇怪的是,它不会产生错误。我在任何不推荐的名单上都找不到。

我刚运行了你的代码,它给我发了一封带有pdf文件的电子邮件。我评论了一些部分。

代码语言:javascript
运行
复制
function onFormSubmit(e){
  //set the email address where the finished document will go.
  var docs_email = "your_email@gmail.com";

  //get information from the newly submited form
  var full_name = 'First Last';
  var age = '99';
  var address = '77 Maple Grove';
  var phone = '800 Call Joe';
  var alt_phone = 'none';
  var email

  //Get the document template and copy it as a new temp document. Save the document ID's
  var copyId = DriveApp.getFileById('Your Document ID Here')
  .makeCopy('Novem3'+' for '+full_name)
  .getId();

  //open the temp document
  var copyDoc = DocumentApp.openById(copyId);
  //go to the temp documents body
  copyDoc.getBody()
  var copyBody = copyDoc.getActiveSection();

  //replace the text in the temp document
/*  copyBody.replaceText('keyFullName', full_name);
  copyBody.replaceText('keyAge', age);
  copyBody.replaceText('keyAddress', address);
  copyBody.replaceText('keyPhone', phone);
  copyBody.replaceText('keyAltPhone', alt_phone);
  copyBody.replaceText('keyEmail', email);
*/
  //save and close the temp document
  copyDoc.saveAndClose();

  //convert the temp document to pdf
  var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

  //Attach PDF and send the email
  var subject = "New Doc's Job Application Submited Online";
  var body = "A new job application has been recieved from " + full_name + ". Primary phone number for this applicant is: " + phone + "";
  GmailApp.sendEmail(docs_email, subject, body, {htmlBody: body, attachments: pdf});

  // Delete temp file
  //DriveApp.getFileById(copyId).setTrashed(true); 
} //End of dunction "onFormSubmit
票数 1
EN

Stack Overflow用户

发布于 2015-11-02 23:24:01

我发现如果你在给自己发邮件,他们可能不会出现在你的收件箱里,所以看一看“发送邮件”,看看它们是否存在。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33486329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档