使用脚本从电子表格更新Google日历

时间:2014-01-21 15:34:55

标签: google-apps-script google-sheets google-calendar-api

我正在尝试从电子表格中的事件更新我的Google日历。

下面是我的代码,它运行时没有错误,但我的日历中没有任何更新,我在行中包含一个单元格,该单元格中包含的数据被记录为应该显示为“是”的事件,这样只有新的事件被转移到日历

function calUpdate() 
{

  var projects = SpreadsheetApp.getActiveSpreadsheet();
  //Spreadsheet that contains event information


  var workCalendar = CalendarApp.openByName("JC Work");
  //calendar that is being updated


  var estimates = projects.getSheetByName("Upcoming Estimates");
  //Sheet that contains event information

  var lastRow = projects.getLastRow();
  //get last row with data from estimates sheet


  var estRange = estimates.getRange(2,1,lastRow,4);
   //set range that contains data


  // process the data
  for (var i;i<=estRange.length;i++) 
  {
      if (estRange.getRange(i,4).getValue().toLowerCase()=="yes"){
      // do nothing
      }
      else {
        // each row contains (A)gc, (B)project name, (C)date and time in date time          number format
        var gc  = estRange.getValue(i,1);  // First column of row
        var project = estRange.getValue(i, 2);  // Second column of row
        var date = estRange.getValue(i,3); //Third column of row

    Browser.msgBox("New Estimate for " + gc , "Project: " + project + "; Bid Date and Time: " + date, Browser.Buttons.OK);
    //Test to see if information is correct

    workCalendar.createEvent("Estimate for: " + gc + project,
        new Date(date),
        new Date(date));
    estRange.getRange(i,4).setValue("Yes")
    //write data to calendar
    }
  }

}

好的,我对代码进行了一些更改,我认为我遇到了一些错误,但它仍无效。

function calUpdate() 
{

  var projects = SpreadsheetApp.getActiveSpreadsheet();
  //Spreadsheet that contains event information


  var workCalendar = CalendarApp.openByName("JC Work");
  //calendar that is being updated


  var estimates = projects.getSheetByName("Upcoming Estimates");
  //Sheet that contains event information

  var lastRow = projects.getLastRow();
  //get last row with data from estimates sheet


  var estRange = estimates.getRange(2,1,lastRow,4).getValues();
  //set range that contains data

//just makeing sure the data is being red correctly 
        var gc  = estRange[0][0];  // First column of row
        var project = estRange[0][1];  // Second column of row
        var date = estRange[0][2]; //Third column of row

        Browser.msgBox("New Estimate for " + gc , "Project: " + project + "; Bid Date and Time: " + date, Browser.Buttons.OK);  

 // process the data
  for (var i;i<=estRange.length;i++) 
  {
      if (estimates.getRange(i+1,4).getValue().toLowerCase()=="yes"){
      // do nothing
      }
      else {
        // each row contains (A)gc, (B)project name, (C)date and time in date time number format
        var gc  = estRange[i][0];  // First column of row
        var project = estRange[i][1];  // Second column of row
        var date = estRange[i][2]; //Third column of row

        Browser.msgBox("New Estimate for " + gc , "Project: " + project + "; Bid Date and Time: " + date, Browser.Buttons.OK);
        //Test to see if information is correct

        workCalendar.createEvent("Estimate for: " + gc + project,
            new Date(date),
            new Date(date));
        estimates.getRange(i+1,4).setValue("Yes")
        //write data to calendar
      }
  }


}

0 个答案:

没有答案