Google script google sheet to calendar TypeError: Cannot find function createEvent in object Calendar. (line 18, file "Code")

Google script google sheet to calendar TypeError: Cannot find function createEvent in object Calendar. (line 18, file "Code")

我试图创建一个 google 脚本,该脚本将根据 google 工作表中单元格内的信息创建日历事件。我已经到了所有东西都被标记和标记的地步,但是发生了一个错误,指出:

TypeError: Cannot find function createEvent in object Calendar. (line 18, file "Code")

这是我写的代码:

function calInsert() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 25;   // Number of rows to process
  var dataRange = sheet.getRange(startRow, 2, numRows, 9);
  var data = dataRange.getValues();
  var cal = CalendarApp.getCalendarsByName( "EC Calendar" );
  for (i in data) {
    var row = data[i];
    var title = row[1];  // First column
    var tstart = row[2]; // Second column
    var tstop = row[3];
    var desc = row[4];       
    var loc = row[5];
    var cmmail = row[6];
    var leamail = row[7];

  var event = cal.createEvent(title, new Date(tstart), new Date(tstop), {description:desc,location:loc,guests:cmmail,guests:leamail}); 

} }

如能提供任何帮助,我们将不胜感激。

var cal = CalendarApp.getCalendarsByName("EC Calendar"); 这会为您提供一组具有该名称的日历。将其更改为:

var cal = CalendarApp.getCalendarsByName("EC Calendar")[0]; //获取正确的日历 这为您提供了第一个带有该名称的日历。我尝试了以下代码:

function calInsert() {
 var sheet = SpreadsheetApp.getActiveSheet();
 var startRow = 2;  // First row of data to process
 var numRows = 2;   // Number of rows to process
 var dataRange = sheet.getRange(startRow, 1, numRows, 5);
 var data = dataRange.getValues();
 var cal = CalendarApp.getCalendarsByName( "calendar ID" )[0];
 for (i in data) {
    var row = data[i];
    var title = row[0];  // First column
    var tstart = row[2]; // Second column
    var tstop = row[3];
    Logger.log(tstop);
    var desc = row[1];       
    var loc = row[4];
   //var cmmail = row[6];
   //var leamail = row[7];

   cal.createEvent(title, new Date(tstart), new Date(tstop),     {description:desc,location:loc}); 
}
}

我可以在日历中创建活动。如果需要,您可以发送 cmmail 和 leamail 到 createEvent。