简体   繁体   English

Google表单可将数据从电子表格和电子邮件中提取给用户

[英]Google Form to pull data from spreadsheet and email to user

I have a spreadsheet containing all of the annual leave balances for each staff member. 我有一个电子表格,其中包含每个工作人员的所有年假余额。 I have a form that the staff will fill out, and I would like it to pull the their data from the spreadsheet and send them an email with the result. 我有一个表格供员工填写,我希望它从电子表格中提取他们的数据,并向他们发送一封包含结果的电子邮件。

I am having trouble with the matching of form data to the spreadsheet data, and extracting the related cells. 我在将表单数据与电子表格数据匹配以及提取相关单元格时遇到麻烦。 Here is the code: 这是代码:

function SendGoogleForm(e) {  
  try {      

    var subject = "Leave Balance Request";  
    var s = SpreadsheetApp.openByUrl("url").getSheetByName("Check Leave");

    var email = e.namedValues["BCA National email address"];
    var sheet =  SpreadsheetApp.openByUrl("url").getSheetByName("Leave Summary");
    var cell = sheet.getRange("F3:F3");
    var getcell = cell.getCell(1,1);
    var pdate = getcell.setValue(e.namedValues['END date of leave requested']);
    var annualvalue = sheet.getRange("H6:H").getValues();
    var emaildata = sheet.getRange("A6:A").getValues();
    var username = e.namedValues["Username"];

    var message = "Your" + " " + e.namedValues["Type of leave requested"] + " " + "balance        is below" + "\n\n";   

    if (username == emaildata)  { message += "Annual Leave" + " : " +    annualvalue               + "\n\n"; }

    MailApp.sendEmail(email, subject, message);

  } 

  catch (e) {
    Logger.log(e.toString());
  }
}

I tried this: How do I search for and find the coordinates of a row in Google Spreadsheets 我尝试了这一点: 如何在Google Spreadsheets中搜索并找到行的坐标

But couldn't get it to work... 但是无法正常工作...

Any suggestions would be greatly appreciated! 任何建议将不胜感激!

When you write var emaildata = sheet.getRange("A6:A").getValues(); 当您编写var emaildata = sheet.getRange("A6:A").getValues(); , you are getting an array of arrays with strings. ,您将获得一个包含字符串的数组数组。 You will need to iterate in a for loop to test each value. 您将需要在for loop进行迭代以测试每个值。

Something like that should work : 这样的事情应该工作:

var message = "Your" + " " + e.namedValues["Type of leave requested"] + " " + "balance        is below" + "\n\n";   
for(var n in emaildata){
  if (username == emaildata[n][0])  { message += "Annual Leave" + " : " +    annualvalue               + "\n\n"; }
}
MailApp.sendEmail(email, subject, message);

} }

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

相关问题 如何从谷歌电子表格中提取数据到网站? - How to pull data from google spreadsheet to a website? 使用Google脚本将数据从一个Google电子表格拉到另一电子表格 - Pull data from one Google spreadsheet to another using Google script 联系表格到 Google 电子表格和电子邮件 - Contact Form to Google Spreadsheet and Email 发送 Email 连同用户提交的 Google Leave 申请表,使用应用脚本、Google 表单、电子表格 - Send Email with the Google Leave request form submitted by the user, using app script, google form, spreadsheet 关于如何根据从其电子表格的 html 形式收到的数据创建 pdf 并通过电子邮件发送 pdf 文件的 Google 应用脚本 - Google app script on how to create a pdf from the data received from an html form of its spreadsheet and send the pdf file via email 将表单数据提交到Google电子表格中 - Submit form data into google spreadsheet HTML表单数据到Google电子表格 - HTML Form Data to Google spreadsheet 如何将数据从 html 表单发送到谷歌电子表格 - How to send data to google spreadsheet from html form 如何使用 JavaScript 将数据从 HTML 表单发送到 Google 电子表格? - How to send data from HTML form to Google Spreadsheet using JavaScript? 如何将电子表格中的所有数据捕获到谷歌表单 - how to capture all data from spreadsheet to google form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM