【问题标题】:How to generate a Google Doc from a Form response, containing all Form items and responses?如何从表单响应中生成包含所有表单项和响应的 Google Doc?
【发布时间】:2014-04-29 15:04:33
【问题描述】:

我目前正在使用以下方式向分发列表发送一封电子邮件,其中包含提交 Google 表单时的标题/问题和相应答案:

function sendFormByEmail(e) {

 // Subject field of email

 var emailSubject = "New Student Case Filed";  

 // Comma-separated list of email addresses for distribution.
 var yourEmail     = "my email address";

 // Spreadsheet key, found in the URL when viewing your spreadsheet.
 var docKey       = "my spreadsheet key";

 // If you want the script to auto send to all of the spreadsheet's editors, set this value as 1.
 // Otherwise set to 0 and it will send to the yourEmail values.
 var useEditors     = 0;

 // Have you added columns that are not being used in your form? If so, set this value to 
 // the NUMBER of the last column that is used in your form.
 // for example, Column C is the number 3
 var extraColumns = 40;

  if (useEditors) {
  var editors = DocsList.getFileById(docKey).getEditors();
  if (editors) { 
   var notify = editors.join(',');
  } else var notify = yourEmail;
 } else {
  var notify = yourEmail;
 }

 // The variable e holds all the submission values in an array.
 // Loop through the array and append values to the body.
 // Need to omit headers with no response*

 var s = SpreadsheetApp.getActive().getSheetByName("StudentCases");
 if (extraColumns){
  var headers = s.getRange(1,1,1,extraColumns).getValues()[0];
 } else var headers = s.getRange(1,1,1,40).getValues()[0];

 var message = "";
 for(var i in headers) {
   message += headers[i] + ' : '+ e.values[i].toString() + '\n\n'; 
 }

现在我还想要创建一个包含标题和响应的 Google 文档。到目前为止,我已经能够创建 Doc、添加标题和添加段落,但现在我还需要在 Google Doc 中复制标题/响应数组。

// Create a new Google Doc named 'Case File' * need to figure out how to pull last name response from form.

 var doc = DocumentApp.create('Case File: Last Name*');

 // Access the body of the Doc, add a paragraph, *need to append array of headers/answers

 var body = doc.getBody().body.appendParagraph(); 

 // Get the URL of the Google Doc to include in Email

 var url = doc.getUrl();

 // Get ID of Doc to attach to email

 var id = doc.getId()

我想解决的另一个问题;我只需要包含响应的标题/问题,因为其中许多不一定保证答案。所以换句话说,如果没有答案,那么不要附加到电子邮件中。

【问题讨论】:

  • StackOverflow 面向简单的技术问题和答案。如果您正在寻找更全面的帮助,您应该考虑在 Apps Script Google+ 社区之一发帖:plus.google.com/s/%22Apps%20Script%22/communities

标签: google-apps-script google-docs google-forms


【解决方案1】:

您似乎提供了一份一般要求列表,但与您尝试得到的结果并没有太大关系。如果您提供有关您所尝试的内容的更多尖锐问题,StackOverflow 将对您有所帮助。

您能分享一下您尝试过的确切代码吗?你的结果是什么?

从高层次上来说,我会继续这个一般的工作流程。

  1. 在您选择的变量命名法 ~FName ~LName 等中使用占位符起草 gDoc 模板。
  2. 在提交新表单时,使用 onFormSubmit 触发器制作 gDoc 模板的副本。
  3. 将复制的 gDoc 中的 ~FName ~LName 占位符替换为表单中捕获的内容
  4. 将复制的 gDoc 保存为 PDF
  5. 通过电子邮件将 PDF 发送到表单提交中提供的电子邮件地址

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2018-05-13
    • 2021-09-20
    相关资源
    最近更新 更多