Google电子表格/日历界面脚本

时间:2013-05-31 18:44:22

标签: google-apps-script google-sheets google-calendar-api

我正在尝试创建一个Google电子表格(带有表单),该表格会将事件上传到Google日历,然后通过电子邮件向表单的提交者发送附加信息。我对电子邮件部分没有任何问题,但是日历接口给我带来了麻烦。

当我尝试运行我的脚本时,它给出了错误消息:“找不到方法(类)直到(字符串)。(第84行,文件”代码“)”这一行的要点是创建一个日历事件使用提交表格中的数据。

以下是第84行变量的定义(在脚本的其他地方声明):

var calId = "5u6ui0kdehtpn5ml5gr9s13260@group.calendar.google.com"; //test calendar ID
var cal = CalendarApp.getCalendarById(calId); //sets the active calendar to calID for adding events
var eventTitle = row[11] //"Event Title" column
var eventStartDate = Utilities.formatDate(new Date(row[12]), "GMT", "MM/dd/yy") //"Calendar Start Date" column
var eventEndDate = Utilities.formatDate(new Date(row[13]), "GMT", "MM/dd/yy");  //"Calendar End Date" column
var eventDescription = "a string for the description"

这是第84行:

cal.createAllDayEventSeries(eventTitle, eventStartDate, CalendarApp.newRecurrence().addDailyRule().until(eventEndDate),{description:eventDescription});

关于我为什么收到此错误或我可以采取哪些措施来纠正错误的想法?

1 个答案:

答案 0 :(得分:0)

您为方法提供了错误的类型。

当您检查RecurrenceRule.until()方法的文档时,您会发现该参数应该是Date对象。在您的代码中,您提供了一个String,其中包含表示日期的文本。解释器命中.until(eventEndDate),并尝试查找接受String参数的方法版本,失败并抛出您看到的错误。

当您为eventEndDate分配值时,您希望它是Date对象。这意味着你可以放弃.formatDate()位,这只是制作一个令人愉悦的字符串。试试这个:

var eventStartDate = new Date(row[12]) // "Calendar Start Date" column
var eventEndDate = new Date(row[13])   // "Calendar End Date" column
相关问题