简体   繁体   English

如何获得通过电子邮件发送到Google表单中的数据?

[英]How can I get the data entered into a Google Form emailed to me?

I made some modifications to a Google Script I found online, but not knowing how to script so well, I'm sure I'm missing something here. 我对在网上找到的Google脚本进行了一些修改,但是不知道如何编写如此出色的脚本,因此我确定这里缺少一些内容。

My goal is to have all the information submitted through a Google Form to then be emailed to me or a group I'll create. 我的目标是将所有信息通过Google表单提交,然后通过电子邮件发送给我或我将创建的网上论坛。

This script here does email me the info, but it's all added as a single line without even mentioning the questions. 此脚本的确向我发送了相关信息,但全部都添加为一行,甚至没有提及问题。

I'm a total newb, but I'm sure this could be solved with some kind of command or event that I'm unaware of. 我是个新手,但是我敢肯定,可以通过某种我不知道的命令或事件来解决。

Take a look: 看一看:

var EMAIL_SENT = "EMAIL_SENT";

function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;  // First column of data to process
var numRow = 1;   // Number of columns to process
var dataRange = sheet.getRange(startRow, 1, numRow, 10)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var message1 = row[1,2,3,4,5];
var message2 = row[2];
var message3 = row[3];
var message4 = row[4];
var message5 = row[5];
var message6 = row[6];
var message7 = row[7];
var message8 = row[8];// Second column
var emailSent = row[10]
 if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
  var subject = "New Hire On The Way!";
MailApp.sendEmail("itgroup@mycompany.com",subject,message1+message2+message3+message4+message5+message6);
  sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);
}
}
}

That whole "EMAIL_SENT" was my attempt at having the script not resend info that was already entered. 整个“ EMAIL_SENT”是我试图让脚本不重新发送已输入的信息。

If there is a better way of doing this, I'd love to hear it. 如果有更好的方法,我很想听听。

Thank you so much! 非常感谢!

You can set this function as a trigger for onFormSubmit in the response sheet. 您可以在响应表中将此函数设置为onFormSubmit的触发器。

Source: Get Google Forms data in an Email Messages 来源: 通过电子邮件获取Google表单数据

function SendGoogleForm(e) { 

    var email = Session.getActiveUser().getEmail();
    var subject = "Google Docs Form Submitted";  

    var s = SpreadsheetApp.getActiveSheet();
    var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
    var message = "";    

    for ( var keys in columns ) 
      message += columns[keys] + ' :: '+ e.namedValues[columns[keys]] + "\n\n"; 

    MailApp.sendEmail(email, subject, message); 

}

if your just wanting the email to have a little more structure you can just add html to the individual messages. 如果您只是希望电子邮件具有更多结构,则可以将html添加到各个邮件中。 Depending how crazy your want to get is up to you. 取决于您想要获得的疯狂程度取决于您。 Here is a simple change that you can try it should have a little more structure. 这是一个简单的更改,您可以尝试更改它的结构。 Replace this with your if statement 将其替换为您的if语句

if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
 var subject = "New Hire On The Way!";
MailApp.sendEmail("itgroup@mycompany.com",subject,message1+"<br />"+"<br />"+"<br />"+message2+"<br />"+"<br />"+"<br />"+message3+"<br />"+"<br />"+"<br />"+message4+"<br />"+"<br />"+"<br />"+message5+"<br />"+"<br />"+"<br />"+message6+"<br />"+"<br />"+"<br />");
 sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);

} }

All I did here is add breaks between your messages. 我在这里所做的只是在您的消息之间添加中断。 This should create some spaces. 这应该创建一些空间。 You can always go crazy with inline css and html. 您总是可以内联css和html疯狂。 www.w3schools.com is always a great place to start for beginners. 对于初学者来说, www.w3schools.com始终是一个不错的起点。 Good Luck and happy coding! 祝您好运,编码愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用粗体文本通过电子邮件发送Google表单数据 - how to have google form data emailed with bold text 如何通过电子邮件将localStorage数据发送到客户端 - how to get localStorage data emailed to client IE7默认表单方法是“GET”。 如何判断它是用户输入还是默认? - IE7 default form method is “GET”. How can I tell if it's user-entered or default? 如何获取提交时的表格数据? - How can I get the data of form on submit? 如何捕获输入到HTML表单字段中的数据? - How do I capture data entered into the field of an HTML form? 如何获取用户在VueJS的这些v文本字段中输入的数据? - How can I get access to the data entered by the user in these v-text-fields in VueJS? javascript:如何提取在此表单中输入的值? - javascript: how can I extract the values entered in this form? 我怎样才能弹出一个jQuery CSS容器,让用户知道数据已成功输入? - How can I get a jquery css container to pop up letting the user know data was successfully entered? 只有在我想要的工作表上输入新数据时,如何才能在 Google Apps 脚本中运行 onChange 或 onEdit? - How can I run onChange or onEdit in Google Apps Script only when new data is entered on the sheet I want? 如何使用表格形式的GET API获取数据 - How Can i Get data using GET API In Tabular Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM