Google drive spreadsheet and calendar invite guest

女生的网名这么多〃 提交于 2019-12-11 10:15:46

问题


Okay, first of all, what I'm trying to do is updating Google sheet and calendar simultaneously. So, let say if there's an update to your spreadsheet there will also be an update to the calendar. However, here's all the things that I failed to do.

  1. If there's changes in the calendar , there will be no changes in the spreadsheet
  2. I'm unable to find code to invite guest to the calendar. So far , all i know is that i need to to use " attendee[] " but I'm unable to find example to show me on how its done. I've found some java code but its different if I'm not mistaken.

So, these will be the order for the spreadsheet

Date Title Start Time End Time Location Description Guest EventID

This one is the code on the google sheets.

function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Export Events",
    functionName : "exportEvents"
  }];
  sheet.addMenu("Calendar Actions ", entries);
};


function exportEvents() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var headerRows = 1;  
  var range = sheet.getDataRange();
  var data = range.getValues();
  var calId = "muiznn@gmail.com"; // calenderID
  var cal = CalendarApp.getCalendarById(calId);
  for (i in data) {
    if (i < headerRows) continue; 
    var row = data[i];
    var date = new Date(row[0]); 
    var title = row[1];           
    var tstart = new Date(row[2]);
    tstart.setDate(date.getDate());
    tstart.setMonth(date.getMonth());
    tstart.setYear(date.getYear());
    tstart.setMinutes( tstart.getMinutes() + 6)
    var tstop = new Date(row[3]);
    tstop.setDate(date.getDate());
    tstop.setMonth(date.getMonth());
    tstop.setYear(date.getYear());
    tstop.setMinutes(tstop.getMinutes() + 6)
    var loc = row[4];
    var desc = row[5];
    var guest = row[6]
    var id = row[7];              



    try 
    {
      var event = cal.getEventSeriesById(id);
      event.deleteEventSeries();
      row[7] = '';    
    }
    catch (e) {

    }

    var newEvent = cal.createEvent(title, new Date(tstart), new Date(tstop), {description:desc,location:loc}).getId();
    row[7] = newEvent;  
    debugger;

   }

  range.setValues(data);
}

If possible , I would some guidance on this , since I'm stuck.


回答1:


For this, if you want to create a new event for each new entry in spread sheet you could use Calender class and create an event.

If you want to edit an already created event and add new guests you could use CalendarEvent class and add guests.

Hope that helps!



来源:https://stackoverflow.com/questions/29936870/google-drive-spreadsheet-and-calendar-invite-guest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!