如何从电子表格发送电子邮件 [英] How to send email from a spreadsheet
问题描述
我在Google Docs上有一个电子表格,其中包含我们正在工作的工作任务。我想要它做的是将整行发送到预期的收件人,但我只能让它发送电子邮件地址后的第一列的信息。所有东西都有到期日期,我希望在接近该日期时发送提醒,但我不知道该怎么做。
任何帮助将不胜感激。 件: 等等。或者你可以建立一个循环。 http ://www.w3schools.com/jsref/jsref_concat_string.asp 为了获得范围,为什么这么难? 相反,试试这个。 I have a spreadsheet on Google Docs with tasks for a job that we are working on at work. What I am wanting it to do is to send the whole row to the intended recipient but I can only get it to send the info from the first column after the email address. Everything has a due date on it and I would like to get it to send a reminder when it gets close to that date but I do not know how to do that. Any help would be greatly appreciated.
Here is the code I have right now:
This piece: And so on. Or you could build a loop. http://www.w3schools.com/jsref/jsref_concat_string.asp And to get the range, why do it the hard way? Instead, try this.
这篇关于如何从电子表格发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
这里是我现在的代码:
pre $ function sendEmails(){
var sheet = SpreadsheetApp .getActiveSheet();
var startRow = 3; //第一行数据处理
var numRows = 2; //要处理的行数
//获取单元格范围A2:B3
var dataRange = sheet.getRange(startRow,1,numRows,2)
//获取每个单元格的值在范围内排。
var data = dataRange.getValues();
for(i in data){
var row = data [i];
var emailAddress = row [0]; //第一列
var message = row [1]; //列B,列C,列D,列E,列F,列G
var subject =Email Test Spreadsheet;
MailApp.sendEmail(emailAddress,subject,message);
$ / code>
var message = row [1];
将只获得数组中的第二个元素(索引1)。您需要遍历该行以获取所有数组元素。
var message = row [1];
message.concat(row [2]);
message.concat(row [3]);
sheet.getRange(A2:B3);
这就是您想要在该行上面的注释中说的范围,尽管它只是4个细胞。 sheet.getRange(A2:G3)
会得到两列到G列。
当然,如果你添加行到表中,每次都要修改代码。
var bottomRow = sheet.getLastRow();
var rangeInA1 =A2:G+ bottomRow;
var dataRange = sheet.getRange(rangeInA1);
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 3; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Column B, Column C, Column D, Column E, Column F, Column G
var subject = "Email Test Spreadsheet";
MailApp.sendEmail(emailAddress, subject, message);
}
}
var message = row[1];
will only ever get the second element (index 1) in the array. You'll need to iterate through the row to get all the array elements.var message = row[1];
message.concat(row[2]);
message.concat(row[3]);
sheet.getRange("A2:B3");
That's the range you said you're trying to get in the comment above that line, although it is only 4 cells. sheet.getRange("A2:G3")
would get two rows out to column G.
Of course, if you add rows to the sheet, you'd have to modify the code every time.var bottomRow = sheet.getLastRow();
var rangeInA1 = "A2:G"+bottomRow;
var dataRange = sheet.getRange(rangeInA1);