1

好的,这是我的导致错误的代码。这似乎只是我尝试添加全天事件的行。我认为这是一个日期格式问题,但我在它下面注释掉的那行是为了测试它而创建的,它导致了同样的错误。所以我很难过。需要更改什么来纠正错误,或者错误的实际含义是什么。

    function cal1() {
      var sheet = SpreadsheetApp.getActiveSheet();
      var startRow = 2;  // First row of data to process
      var numRows = 300;   // Number of rows to process
      var dataRange = sheet.getRange(startRow, 1, numRows, 26); //What data will be used
      var data = dataRange.getValues();
      var cal = CalendarApp.getCalendarsByName("Production Schedule"); //Gets the correct calendar
    for (i in data) {
      var row = data[i];
      var title = row[4];  // Column with Title
      var desc = row[3];       // Column with Description
      var date = row[8];   //Column with Date
      var loc = row[5];    //Column with Location
      cal.createAllDayEvent(title, date, {description:desc,location:loc});
      //cal.createEvent("Test", new Date("3/10/2010 14:30:00"), new Date("3/10/2010 14:30:00"));  
  }
 }
4

3 回答 3

1
  var cal = CalendarApp.getCalendarsByName("Production Schedule"); //Gets the correct calendar

这为您提供了一组具有该名称的日历(因为日历可以共享名称,因此可以有多个)。尝试这个:

  var cal = CalendarApp.getCalendarsByName("Production Schedule")[0]; //Gets the correct calendar

这将为您提供第一个(可能只有)具有该名称的日历。

于 2012-09-20T16:53:59.180 回答
1

如果您不确定“日期”变量实际上是您可以使用的日期

  cal.createAllDayEvent(title, new Date(date), {description:desc,location:loc});

也就是说,很容易用记录器检查

Logger.log(date)

应以形式返回日期值Tue Sep 18 03:00:00 PDT 2012

于 2012-09-21T19:31:58.373 回答
0

我有同样的问题getCalendarsByName。相反,我使用getCalendarById它并很好地解决了。我认为日历名称可能会引起一些混乱和错误。

您可以在日历设置中找到您的日历 ID,例如:123xyz@group.calendar.google.com

脚本将如下所示:

var cal = CalendarApp.getCalendarById("123xyz@group.calendar.google.com");
于 2012-12-16T05:20:04.917 回答