提交表单

时间:2016-12-01 21:02:32

标签: javascript google-apps-script

对于学校,我们正在进行葡萄酒销售。我创建了一个表单,以便人们可以订购他们想要的葡萄酒。  我在网上搜索了两个多星期,以便向填写表格的人发​​送一份有效的自动确认邮件。 在此邮件中,订购的总金额会立即填写。这就是我无法在Google表单中使用自动确认邮件的原因。我尝试了其他人提供的几种解决方案,但都没有。 到目前为止,我使用了一个脚本,该脚本在按下Google表格中的按钮后运行,但不是自动...在表单提交时设置触发器 我该如何调整代码?

  function sendEmails() {


  var sheetname = "Bestellingen";
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(sheetname);

  var startRow = 2;  // First row of data to process
  var numRows = 150;   // Number of rows to process
  // Fetch the range of cells A2:B3
  var dataRange = sheet.getRange(startRow, 1, numRows, 5)

  Logger.log("Data Range: " + dataRange.getA1Notation());

  // 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 emailAddress = row[1];  // First column = email
    var name = row[2];          // Second column = name
    var emailSent = row[3];     // Third column
    var totals = row[4];        //Fourth column = totals count in excel
    var sendername;
    var message;

//this is your message

 message = "Beste " + name + ",\n\nWij hebben uw bestelling goed ontvangen! \nGelieve het bedrag van: " + totals + " over te schrijven op het rekeningnummer van de ouderraad KBC BEXX XXXXX XXXX \nMocht u nog iets willen veranderen aan uw bestelling of een opmerkingen  hebben kunt u altijd een reply sturen op deze bevestigingsmail \nWij hopen dat u van uw wijn(en) zal genieten, \nSanté \n\nHet feestcomitée \n\n"

        // This will show up as the sender's name
        sendername = "Wijnverkoop Freinetschool De boomgaard";

    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = "Wijnbestelling de Boomgaard";
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 4).setValue(EMAIL_SENT);

// Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

我会在发现它后立即发布这项工作的作者..

链接到Google表格 https://docs.google.com/spreadsheets/d/13e10IgUC8Toexy1ia8plWOWPrq62dxTAMZfSy0PwDDM/edit?usp=sharing

1 个答案:

答案 0 :(得分:-1)

您是否尝试过Google表格?我认为它会让你的生活更轻松。