Connect Google Calender to Spreadsheets using Apps Script

Learn how to easily connect your Google Calendar to your Google Spreadsheet using Apps Script! There's a Hangout on Air video I did along with posting the source code. Hope you all enjoy :)


Source code

As mentioned in the video here is the source code!
function listCal(){
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  cell = sheet.getRange("A1");

  cApp = CalendarApp.getAllCalendars();
  
  for (var b = 0;b < cApp.length;b++){
    cell.offset(0,b).setValue(cApp[b].getName());
    
    var events = cApp[b].getEvents(new Date("March 1, 2012 EST"), 
            new Date("July 22, 2012 EST"));
  
      for ( var j=0;j< events.length;j++){
        cell.offset(j+1,b).setValue(events[j].getTitle());
      }
  } 
      
  
}

Popup Window Source Code

Pops up a window, asks for a number, saves it to cell and gives it back to you (plus one).
function example() {
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  
  var myValue = Browser.inputBox("Enter a number"); 
  sheet.getRange("A1").setValue("Number entered:");
  
  var b1Range = sheet.getRange("B1");
  b1Range.setValue(myValue);
  
  var valueToShow = b1Range.getValue() + 1;
  
  Browser.msgBox("The value you entered plus one is: " + valueToShow);
  
}

Popular posts from this blog

Connect to Gmail with Apps Script

How to create a Chrome Extension

Apps Script on tablets