Home > database >  Create event google calendar from spreadsheet
Create event google calendar from spreadsheet

Time:08-22

I’m trying to create a event in my google calendar from a cell on a spreadsheet. This is what I have so far, but is not working. Any ideas?

function createCalendarEvent() {
let XCalendar = CalendarApp.getCalendarById("calendaiID");
let sheet = SpreadsheetApp.getActiveSheet();

let task = sheet.getDataRange().getValues();
task.splice(0.1);

task.forEach(function(entry){
XCalendar.createAllDayEvent(entry[0],entry[1])
})
}

This is how the sheet looks.

https://img.codepudding.com/202208/5aeb38099e4441b8b191cdf4cfb30514.png

CodePudding user response:

Try this:

function createCalendarEvent() {
  let cal = CalendarApp.getCalendarById("calendaiID");
  let sheet = SpreadsheetApp.getSheetByName("Sheet Name");
  let vs = sheet.getDataRange().getValues();
  vs.forEach(r => {
    cal.createAllDayEvent(r[0], new Date(r[1]))
  });
}

CodePudding user response:

Assuming that B2 and B3 have Date values and not Text values, replace task.splice(0.1); by task.splice(0, 1); (comma instead of dot) or by task.shift(); (I prefer the last)

function createCalendarEvent() {
  let XCalendar = CalendarApp.getCalendarById("calendaiID");
  let sheet = SpreadsheetApp.getActiveSheet();

  let task = sheet.getDataRange().getValues();
  task.shift();

  task.forEach(function(entry){
    XCalendar.createAllDayEvent(entry[0],entry[1])
  })
}
  • Related