在插入时运行Google表格脚本

les*_*san 0 google-sheets google-drive-api google-forms

因此,我有一个Google表单,并根据提交的表单数据生成响应,我希望将该响应通过电子邮件发送给填写表单的人。有没有一种方法可以在发送新行时发送电子邮件插入答案纸?

sim*_*oes 7

我过去完成此操作的方式是编写一个简单的Google docs脚本来侦听电子表格的onChange触发器,并发送包含该工作表行内容的电子邮件。具体步骤如下:

  1. 在您的Google工作表打开的情况下,转到工具>脚本编辑器...

在Google表格中打开脚本编辑器

  1. 这将带您到与此文件关联的脚本,您可以在其中编写一个简单的函数来发送工作表最后几行的内容。像下面这样的东西会起作用:
function sendEmailOfLastEditedRow() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];

  var lastRow = sheet.getLastRow();
  var numRows = 1;   // Number of rows to process
  var cols = sheet.getLastColumn();


  // Fetch the range of cells A2:D5
  var dataRange = sheet.getRange(lastRow, 1, numRows, cols)

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();

  // Fetch your row as an array
  var lastRowData = data[0];

  // Format data by separating values into comma separated list for email
  var emailContent = lastRowData.join(",");

  // Send an email (change this to your email)
  MailApp.sendEmail('alex@simoes.com', 'Email subject', emailContent);

  // Log contents for debugging      
  Logger.log(emailContent);
}
Run Code Online (Sandbox Code Playgroud)
  1. 在编辑Google表格时,在脚本编辑器中添加触发器以运行此功能:编辑>当前项目的触发器

添加谷歌表触发器