在电子表格中,列J
具有要求提取的公司名称。我想要的是公司名称要求提货是电子邮件正文。例如,这将输入到单元格J10
中。
输入公司名称时,只需发送一次。我已将脚本设置为运行" onEdit"。
以下是我到目前为止,正如您将看到的,问题在于第14行 - var body
:
/* This function send an email when a specified range is edited
* The spreadsheets triggers must be set to onEdit for the function
*/
function sendNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// Get Active cell
var mycell = ss.getActiveSelection();
var cellcol = mycell.getColumn();
var cellrow = mycell.getRow();
// Define Notification Details
var recipients = "emailaddressn@domain.com";
var subject = "Pickup Entered";
var body = ss.getActiveSelection() + " has a pickup.";
if (cellcol == 10) {
// Send the Email
MailApp.sendEmail(recipients, subject, body);
}
} // End sendNotification
因此,最终驱动程序会收到来自Google表格的电子邮件,主题为" Pickup Entered"电子邮件的正文是"公司ABC有一个提货"。
更新: 我找到了类似的脚本并对其进行了修改以适应。这完全符合我的要求:
function sendNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
if(sheet.getName()=='Sheet1'){
var cell = ss.getActiveCell();
var cellcol = cell.getColumn();
if(cellcol == 10){
var cellvalue = ss.getActiveCell().getValue().toString();
var recipients = "emailaddress@domain.com";
var subject = 'Pickup Requested '+cellvalue;
var body = 'A new Pickup has been placed for ' + cellvalue + '. Please
coordinate with dispatch.';
MailApp.sendEmail(recipients, subject, body);}
}
}
由于
答案 0 :(得分:0)
您需要先将范围转换为HTML表格。
注意:
SpreadsheetApp.getActiveRange()
获取菜单的示例代码:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Send selection', 'sendNotification')
.addToUi();
}