這是一種獲得你所要求的方法。每行的發送電子郵件按鈕以及來自該行的隨附數據。
Code.gs
function getEmails()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rg=sh.getDataRange();
var vA=rg.getValues();
var br='<br />';
var s='<table border="1">';
s+=Utilities.formatString('<tr><td>%s</td><td>%s</td><td>%s</td><td> </td></tr>', vA[0][0],vA[0][1],vA[0][2]);
for(var i=1;i<vA.length;i++)
{
s+='<tr><td>' + vA[i][0] + '</td><td>' + vA[i][1] + '</td><td>' + vA[i][2] + '</td><td>';
s0=Utilities.formatString('\'%s\',\'%s\',\'%s\'', vA[i][0], vA[i][1], vA[i][2])
s+='<input type="button" value="Email Row ' + Number(i + 1) + '" onClick="sendMyEmail(' + s0 + ');" /></td></tr>';
}
s+='</table>';
return s;
}
function showMy1Dialog()
{
var ui=HtmlService.createHtmlOutputFromFile('myemail');
SpreadsheetApp.getUi().showModelessDialog(ui, 'Title')
}
function sendEmail(email,subj,body)
{
SpreadsheetApp.getActive().toast(email + ', ' + subj + ', ' + body);
MailApp.sendEmail(email,subj,body);
Logger.log('\'%s\',\'%s\',\'%s\'',email,subj,body);
}
myemail。HTML
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
google.script.run.withSuccessHandler(displayEmails).getEmails();
});//gets data from spreadsheet on document ready
function displayEmails(hl)
{
document.getElementById('mydiv').innerHTML=hl;
}
function sendMyEmail(email,subj,body)
{
google.script.run.sendEmail(email,subj,body);
}
console.log('My Code');
</script>
</head>
<body>
<div id="mydiv">
</div>
<input type="button" value="Close" onclick="google.script.host.close();" />
</body>
</html>
這裏的對話框是什麼樣子:
所以將這個只是發送的所有電子郵件一次(即不會只是你的單一功能運行每次都行)? – theforestecologist
這會針對您的問題發送單個選定行的電子郵件。不過,您可以重寫循環以發送多個選定行的單個消息。 – Brian
好極了!這就是我想要的。謝謝! :) – theforestecologist