вторник, 20 июля 2010 г.

2. Here is the complete source code for the App Script.

http://test.beloitsg.com/?p=472

function happyBirthday() {

var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = (sheet.getLastRow())-1;
var range = sheet.getRange(2, 3, lastRow); // date in the DOB Column
var dates = range.getValues();
var today = new Date();
var cellDate = null;

var firstName = "";
var emailAddress = "";
var body = "";
var subject = "";

for(i in dates)
{
var date = dates[i];
cellDate = new Date(date);
var row = Math.ceil(parseInt(i) + 2); // Spreadsheet range and array index are offset

if(today.getMonth() == cellDate.getMonth()
&& today.getDate() == cellDate.getDate())
{
firstName = (sheet.getRange("A"+ row)).getValue();
emailAddress = (sheet.getRange("D" + row)).getValue();

subject = "Happy Birthday, " + firstName;
body = firstName +
"/nThanks for all the great artwork. Enjoy your special day!\n";

MailApp.sendEmail(emailAddress, subject, body);
}
}
} ​

Комментариев нет:

Отправить комментарий