我是Java语言编程的新手,所以这对我来说是一项艰巨的任务-但是我觉得我可以在一些帮助和指导下完成它-我通常使用vb,vba,c#进行编程。

因此,无论如何,我的工作同事问我是否可以做一些基本上可以告诉他们谁在度假/今天有半天的事情-目前我可以发送一封电子邮件-但是涉及到读取单元格和行。我无能为力,这就是我被困住的地方。

这是我的电子表格

https://docs.google.com/spreadsheet/ccc?key=0Ao7GdcoXMWiHdDNxY1k2X1hyYkhkQ210QldBeHZqaFE&usp=sharing

摘要只是所有工作表的整体视图-它显示某人在一个月的快速查看中拥有多少假期/半天/病假天。
通过使用以下选项卡更新此值:月选项卡中的键H-假期,BH-银行预提证券,HD-半天,S-生病日,HS-半生病日和缺席。

现在,进入我想要实现的目标。假设今天是2012年12月20日,比尔·鲍勃今天在放假-我想发送一封电子邮件说这件事-目前,我已经设置了要发送的电子邮件正文,并且这种方法有效(有点,该邮件正文只是缺少谁是在假期,谁在半天)-我将如何获取此信息-我知道我需要获取今天的日期,然后检查该月并检查H或HD列,然后再检查该行以找出谁然后将其存储在某个位置的变量中,然后再编译一个列表以添加到消息中。

我将如何去做呢?

// Variables for the Date
var today = new Date();
var dd = today.getDate(); // Get todays date
var mm = today.getMonth()+1; // Get todays month - January is 0!

// Variables for the email
var sendEmail = false;
var emailAddress = "";
var subject = "Daily Holiday Summary";
var messagePT1 = "Good Morning,\n\nThe following people have half a day today\n\n";
var messagePT2;
var messagePT3 = "\n\nThe following people are on holiday today\n\n";
var messagePT4;
var messagePT5 = "\n\nMany thanks,\nThe Holiday Spreadsheet";
var fullMessage;

// Variables for the sheets
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheets()[0]);

function main() {
  // This is the main function and will be the one that is ran
  findMessagePT2();
  findMessagePT4();
  sendEmail();
}

function findMessagePT2() {
  // This is the function for finding the people on half a day today

}

function findMessagePT4() {
  // This is the function for finding the people on holiday today
}

function sendEmail() {
  // This is the send email function and will send the email
  if (sendEmail == true){
    fullMessage = messagePT1 + messagePT2 + messagePT3 + messagePT4 + messagePT5;
    MailApp.sendEmail(emailAddress, subject, fullMessage);
  }
}


这是我当前拥有的代码,如果找不到假期或半天的任何人,我不希望发送该消息-好像我是某人一样,希望该消息发送,因此中的if语句sendEmail函数。

最佳答案

我也在谷歌上发布了这个问题,以寻求更多帮助,

https://productforums.google.com/forum/#!msg/docs/FQy-17QD-cc/eO5oZzbuACsJ

正确的方法是。

var s = sheet.getSheets()[mm];
var col=dd+1;
var lastrw=s.getDataRange().getLastRow();
var name;
var code;
for (var i=3; i<=lastrw; i++){
   name=s.getRange(i,1).getValue();
   code=s.getRange(i,col).getValue();
   if (code=="H") {messagePT2+=" name";}
}

10-01 04:53
查看更多