简体   繁体   English

谷歌表格脚本自动定位具有今天日期的单元格,复制整行并通过电子邮件发送

[英]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:在那里你可以找到两个触发器:

  • Google Sheets Events - Form Submit Google 表格活动 - 表单提交
  • Google Form Events - From Submit Google 表单事件 - 从提交

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.

相关问题 如何基于单个单元格编辑(Google Script / GAS)通过电子邮件发送电子表格中的整行数据 - How to send whole row of data in my spreadsheet via email based on single cell edit (Google Script / GAS) 通过for循环谷歌表格脚本将行复制到另一张表格 - Copy row to another sheet via for loop google sheets script Google 表格 - 当 R 列中的单元格小于或等于 0 时发送 email 的脚本 - Google Sheets - Script to send email when the cells in column R are less than or equal to 0 使用谷歌表和脚本发送电子邮件 - use google sheets and script to send email 谷歌应用脚本表 if 语句发送 email - Google apps script sheets if statement to send email Google Sheets Apps Script Copy Row of Data 如果日期与标签名称相同 - Google Sheets Apps Script Copy Row of Data If date same as tab name 是否可以编写脚本来根据该行中的日期复制、粘贴和删除整行? (谷歌表格) - Is it possible to write a script to copy, paste, and delete entire rows based on a date within that row? (Google Sheets) Google表格脚本:如何每天自动复制公式 - Google Sheets script: how to automatically copy down formulas each day Google表格电子邮件脚本 - Google Sheets Email script Google表格脚本:自动将一行删除到另一张表格中 - Google Sheets Script : Automatically remove a row into another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM