Google脚本通过电子邮件形式向用户提供答案和问题 [英] Google Script to email form answers and questions to a user

查看:265
本文介绍了Google脚本通过电子邮件形式向用户提供答案和问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的脚本,向通过Google表单填写调查问卷的用户发送电子邮件。他们将接受调查,答案被记录在电子表格中,这个脚本会通过电子邮件向他们发送问题副本(标题),以及他们的答案(应该成为表格的最后一行。)



发送给它的电子邮件将成为最后一列,这不包含在电子邮件中。



这是我正在努力的脚本来完成这项工作:

  function sendFormByEmail(e){

var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();

var emailSubject =EMAIL-SUBJECT-HERE;
var yourEmail =CURRENTLY-JUST-A-STATIC-EMAIL-ADDRESS; //从field.value得到这个,然后把这个字段从被包含在电子邮件中删除(只做第一列)...


var headers = headersRange.getValues( )[0]; // google api获取标题值。

var lastRow = s.getLastRow();

var message + = headers.toString();
message + =(headersRange.getValue()[last])。toString(); //应该得到最后一行数据?

MailApp.sendEmail(yourEmail,emailSubject,message);


解决方案

您可能会发现它很难阅读所有问题在一行中的电子邮件结果,并在另一行中阅读所有问题。

通过头文件和头文件循环很容易。如果您愿意,可以跳过电子邮件地址。

 函数sendFormByEmail(e){

var emailSubject =EMAIL-SUBJECT-HERE;
var emailQ = 1; //电子邮件地址的列号

var headers = SpreadsheetApp.getActiveSheet()。getDataRange()。getValues()[0]; // google api获取标题值。

var message =您的调查回复:\\\
\\\
;

//打印问题& (i = 0; i< headers.length; i ++){
if(i == emailQ)continue; //跳过电子邮件地址
message + = headers [i] +\\\

+ e.values [i] +\\\
\\\
;
}

MailApp.sendEmail(e.values [emailQ],emailSubject,message);
}


I am trying to make a simple script that sends an email to a user who fills out a survey through a Google Form.

They will take the survey, answers are recorded in a spreadsheet, and this script will email them a copy of the questions (the headings), along with their answers (Should be the last row of the table.)

The email it is sent to was going to be the last column, which is not included in the email.

This was the script I was working on to get this working:

function sendFormByEmail(e) {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var s = ss.getActiveSheet();

 var emailSubject = "EMAIL-SUBJECT-HERE";  
 var yourEmail    = "CURRENTLY-JUST-A-STATIC-EMAIL-ADDRESS"; //get this from a field.value then just cut off that field from being included in the email (just do column-1)...


 var headers = headersRange.getValues()[0];  //google api to get the header values.

 var lastRow = s.getLastRow();

 var message += headers.toString();
 message += (headersRange.getValue()[last]).toString(); //should get the last row of data?

  MailApp.sendEmail(yourEmail, emailSubject, message); 
}

解决方案

You will probably find it hard to read the results of an email with all the questions in one line, and all answers in another.

It's easy to loop through the headers & form values at once, and just skip over the email address if you wish.

function sendFormByEmail(e) {

  var emailSubject = "EMAIL-SUBJECT-HERE";  
  var emailQ = 1;  // Column number with email address

  var headers = SpreadsheetApp.getActiveSheet().getDataRange().getValues()[0];  //google api to get the header values.

  var message = "Your survey responses:\n\n";

  // Print Questions & Answers in pairs
  for (i=0; i < headers.length; i++) {
    if (i == emailQ) continue; // skip email address
    message += headers[i]+"\n"
             + e.values[i]+"\n\n";
  }

  MailApp.sendEmail(e.values[emailQ], emailSubject, message); 
}

这篇关于Google脚本通过电子邮件形式向用户提供答案和问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆