Home > Net >  How to add a description into google calendar from google sheet
How to add a description into google calendar from google sheet

Time:10-14

I'm creating events in a google calendar via a worksheet in google sheets (I use Gsuite / google workspace). I have the following script which works well, however, I need the description to go into google calendar as well. At the moment only the title, start, end and location are going over.

How can I edit my script so that the description goes into the event?

enter image description here

function create_Events(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Test");
  var last_row = sheet.getLastRow();
  var data = sheet.getRange("A1:E"   last_row).getValues();
  var cal = CalendarApp.getCalendarById("[email protected]");
  //Logger.log(data);

  for(var i = 0;i< data.length;i  ){
    //index 0 =
    var event = CalendarApp.getDefaultCalendar().createEvent(data[i][0],
    new Date(data[i][1]),
    new Date(data[i][2]),
    {location: data[i][3]});
 Logger.log('Event ID: '   event.getId());

    
  }

}

CodePudding user response:

Try it this way:

function create_Events() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName("Test");
  var vs = sh.getRange("A1:E"   sh.getLastRow()).getValues();
  var cal = CalendarApp.getCalendarById("[email protected]");
  vs.forEach(([t, s, e, l, d]) => {
    cal.createEvent(t, new Date(s), new Date(e), { description: d, location: l });
  });
}
  • Related