【问题标题】:Googlesheets: I need to assign a script to textbox that sends an email to an email address located in another spreadsheetGooglesheets:我需要为文本框分配一个脚本,该脚本将电子邮件发送到另一个电子表格中的电子邮件地址
【发布时间】:2017-04-17 02:12:40
【问题描述】:

我相信这会让一些人感到沮丧,我很抱歉。我没有任何编码背景,这将是我尝试过的第一个脚本之一。再次感谢您的帮助!

我需要完成的是为一个文本框分配一个脚本,该文本框发送一封电子邮件,地址位于另一个电子表格中。

这里是设置:图 1。这是电子表格和标签,我希望使用位于“游戏内名称”右侧的文本框(带有 E)发送电子邮件地址

图 1.) http://imgur.com/a/8nVzl

“游戏内名称”已从单独的电子表格中导入。如图 2 所示,我将这个单独的电子表格的网址放在当前电子表格的单独选项卡中。

图 2(左侧)和图 3(右侧)因为我的声誉不是 10:http://imgur.com/a/q2bsH

您可以在图 3 中看到我从第二个电子表格中导入的数据(“游戏内名称”和“声望”)。但是我不想以这种方式导入电子邮件地址。

我想要一个脚本,它可以从主电子表格发送一封电子邮件,并使用“播放器密钥输入”选项卡中的电子表格密钥 URL 从第二个电子表格中提取电子邮件地址。

我有一个尝试实现此目的的代码示例,目前只是作为喜剧缓解这件事的焦虑。

再一次,如果这是一个写得不好/解释不清的问题,我很抱歉。我对编码很糟糕。我非常感谢任何意见!

【问题讨论】:

  • 主电子表格是Test Prestige Calculator 还是Player Key Input 上引用的电子表格?你需要这个只为那个玩家The living Tribunal工作吗?为什么Player Key Input 表格上没有球员姓名?电子邮件的内容应该是什么?另外,也许您可​​以发布到目前为止的代码。

标签: email google-apps-script google-sheets


【解决方案1】:

我们能够使用这个脚本让它工作:

    /**
 * This is a utility function that sends an email.
 * It requires a To address, a Subject, and the message Body.
 */
function sendEmail(to, subject, body) {
  // The Reply To address is the default address that appears when a user replies to the email.
  // If not set to a bogus email, it probably defaults to the owner of the sheet!
  var replyTo = "donotreply@mail.com"

  // Send the email!
  MailApp.sendEmail(to, replyTo, subject, body)
}


/**
 * This function is an example of a boilerplate message that you can send.
 * You could duplicate this function for other types of messages.
 */
function sendAllianceMessageToUser(row) {
  var user = getUserInfoFromRow(row);

  sendEmail(user.email, "MCOC Alert", user.name+",\n\nPlease log on to MCOC and check AQ/AW!");
}


/**
 * This utility function will retrieve a user's info when supplied with a row number.
 * The row number must match the rows on the "Roster/Prestige" sheet.
 * This function will not need to change unless the structure of the sheets change.
 */
function getUserInfoFromRow(row) {
  // Keep a reference to the current active sheet
  //var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.openById('1McfUWHPCgh7XWtLgZX6mcnLs_o1MQprBOKbHiwNsVEo').getSheetByName('Roster/Prestige');

  // Grab the sheet key in the row that was provided. (In this case, column L)
  //var skey = sheet.getRange('L'+row).getValue();
  var skey = sheet.getRange('L4').getValue();

  Logger.log(skey);

  // Open the remote sheet using the ID that was retrieved earlier.
  var remote = SpreadsheetApp.openById(skey).getSheetByName('Sheet1');
  // Grab the necessary cell values
  var ign   = remote.getRange('C2').getValue();
  var email = remote.getRange('C4').getValue();

  var user = new Object();
  user.name = ign;
  user.email = email;
  user.sheet_key = skey;

  return user;
}


/**
 * These functions are generic image click handlers for each image.
 * Each image will call a function based on which row it is placed over.
 * MOVING IMAGES WILL BREAK THIS!
 */
function row3_clicked() { sendAllianceMessageToUser('3'); }
function row4_clicked() { sendAllianceMessageToUser('4'); }
function row5_clicked() { sendAllianceMessageToUser('5'); }
function row6_clicked() { sendAllianceMessageToUser('6'); }
function row7_clicked() { sendAllianceMessageToUser('7'); }
function row8_clicked() { sendAllianceMessageToUser('8'); }
function row9_clicked() { sendAllianceMessageToUser('9'); }
function row10_clicked() { sendAllianceMessageToUser('10'); }
function row11_clicked() { sendAllianceMessageToUser('11'); }
function row12_clicked() { sendAllianceMessageToUser('12'); }
function row13_clicked() { sendAllianceMessageToUser('13'); }
function row14_clicked() { sendAllianceMessageToUser('14'); }
function row15_clicked() { sendAllianceMessageToUser('15'); }
function row16_clicked() { sendAllianceMessageToUser('16'); }
function row17_clicked() { sendAllianceMessageToUser('17'); }
function row18_clicked() { sendAllianceMessageToUser('18'); }
function row19_clicked() { sendAllianceMessageToUser('19'); }
function row20_clicked() { sendAllianceMessageToUser('20'); }
function row21_clicked() { sendAllianceMessageToUser('21'); }
function row22_clicked() { sendAllianceMessageToUser('22'); }
function row23_clicked() { sendAllianceMessageToUser('23'); }
function row24_clicked() { sendAllianceMessageToUser('24'); }
function row25_clicked() { sendAllianceMessageToUser('25'); }
function row26_clicked() { sendAllianceMessageToUser('26'); }
function row27_clicked() { sendAllianceMessageToUser('27'); }
function row28_clicked() { sendAllianceMessageToUser('28'); }
function row29_clicked() { sendAllianceMessageToUser('29'); }
function row30_clicked() { sendAllianceMessageToUser('30'); }
function row31_clicked() { sendAllianceMessageToUser('31'); }
function row32_clicked() { sendAllianceMessageToUser('32'); }

function test() {
  sendAllianceMessageToUser('4'); // Testing!
}    

【讨论】:

    【解决方案2】:

    “从另一个电子表格中提取电子邮件地址”这个问题我会使用一个公式将其复制过来。然后分配一个脚本以通过电子邮件发送地址。我不确定您将如何通过脚本从另一张表中提取信息。

    以下公式会将 A1 中的电子表格数据提取到您指定的单元格中。

    =IMPORTRANGE("YOURSHEETID","Sheet1!A1:A")
    

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      相关资源
      最近更新 更多