[英]Google Sheets script to automatically locate cells with todays date, copy the whole row and send it via email
I've built a reporting tool with google forms, where everyday I fill the forms, and the responses go to a spreadsheet.我已经用谷歌表单构建了一个报告工具,每天我都会填写表单,并将回复发送到电子表格。 The spreadsheet has timestamp on column A, and the rest of the columns are the answers to the questions from the form.
电子表格在 A 列上有时间戳,其余列是表单中问题的答案。
I'm trying to write a script that will send me everyday at a specific time an e-mail with an excel file/google sheet link, which will basically have a copy of all the answers from today's forms.(with the date stamp of the current day).我正在尝试编写一个脚本,该脚本将每天在特定时间向我发送一封带有 excel 文件/谷歌表链接的电子邮件,该电子邮件基本上包含今天表格中所有答案的副本。(带有日期戳当天)。
Can anyone help me get started with that?任何人都可以帮助我开始吗?
Thanks in advance!提前致谢!
What you need is你需要的是
Here is a sample code incorporating this features, I encourage you to become more familiar with Apps Script, so that you can adapt this code to your needs:这是包含此功能的示例代码,我鼓励您更加熟悉 Apps 脚本,以便您可以根据需要调整此代码:
function bindATimeTriggerToMe() {
var sheet = SpreadsheetApp.openById("PASTE-ID-OF-SPREADSHEET").getSheetByName("PASTE-NAME-OF-SHEET");
var timestamps = sheet.getRange(1,1,sheet.getLastRow(), 1).getValues();
var today = new Date();
var i;
for (i = timestamps.length-1; i > 0; i--){
var day = timestamps[i][0];
if (day.setHours(0,0,0,0) != today.setHours(0,0,0,0)){
var firstRow = i + 2;
break;
}
}
if (firstRow){
var rows = sheet.getLastRow()-firstRow+1;
var columns = sheet.getLastColumn();
var values = sheet.getRange(firstRow, 1, rows, columns).getValues();
var newSheet = SpreadsheetApp.create("results from "+ today);
newSheet.getSheetByName("Sheet1").getRange(1, 1, rows, columns).setValues(values);
var url = newSheet.getUrl();
var recipient ="XXX@gmail.com";
var subject = "results from " + today;
var body = "Click on the following link: "+url;
GmailApp.sendEmail(recipient, subject, body)
}
}
I think, that you must start to write code.我认为,您必须开始编写代码。
First I recommend reading about Events
from here .首先,我建议从这里阅读有关
Events
的信息。 There you can find two triggers:在那里你可以找到两个触发器:
Pay attention to the difference between two types of trigger: simple and installable注意两种触发器的区别:简单和可安装
Chose one of them, and use it for triggering some MailApp.sendEmail()
function选择其中之一,并用它来触发一些
MailApp.sendEmail()
函数
Then i highly recommend to read documentation of SpreadSheet, Sheet and Range classes and try to write some code.然后我强烈建议阅读 SpreadSheet、Sheet 和 Range 类的文档并尝试编写一些代码。 When you catch a problem - write here with a piece of code that didn't work and describe your problem.
当您遇到问题时 - 在这里写一段不起作用的代码并描述您的问题。
Good luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.