title: How to synchronize Google Calendar & Spreadsheet with Script
body: <p>I am trying to create a Google Apps Script that keeps a Google Calendar and a "master spreadsheet" on Drive synchronized -- is this possible? I found these two posts:</p>
  
  <ul>
  <li><p><a href="http://blog.ouseful.info/2010/03/04/maintaining-google-calendars-from-a-google-spreadsheet/" rel="nofollow">http://blog.ouseful.info/2010/03/04/maintaining-google-calendars-from-a-google-spreadsheet/</a></p></li>
  <li><p><a href="http://blog.ouseful.info/2010/03/05/grabbing-google-calendar-event-details-into-a-spreadsheet/" rel="nofollow">http://blog.ouseful.info/2010/03/05/grabbing-google-calendar-event-details-into-a-spreadsheet/</a></p></li>
  </ul>
  
  <p>I'm quite sure this could be done using a lot of if statements and logic, but maybe there's a simpler way?</p>
  
  <p>I ended up just providing the following simple script. All that was really necessary was adding events based on two columns, and this would've taken too long to develop.</p>
  
  <pre><code>function onOpen() {
    //spawns a menu with a button that triggers AddToCal
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    var entries = [{
      name : "Add event to calendar",
      functionName : "AddToCal"
    }];
    sheet.addMenu("Data To Calendar Plugin", entries);
  };
  
  function AddToCal(){
  
    //get the current row
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var cell = ss.getActiveCell();
    var R = cell.getRow();
  
    //grab values for current row to pass to calendar event
    var date_of_event = ss.getRange('G'+R).getValue();
    var date = new Date(date_of_event);
    var event_title = ss.getRange('A'+R).getValue();
    //access the calendar
    var cal = CalendarApp.getCalendarById('[IDREMOVED]');
    cal.createAllDayEvent(event_title,date);
  
    ss.toast("Event added to " + cal.getName());
    }
  </code></pre>