我对编码非常基本,很抱歉,如果这对您来说非常明显。 我的要求是如何获得"客人"使用CalendarEvent,getGuestList类? https://developers.google.com/apps-script/reference/calendar/calendar-event#getGuestList%28%29
代码测试1:
// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)
for (var i=0;i<events.length;i++)
{
var row=i+2;
// Matching the "header=" entry above, this is the detailed row entry "details=", and must match the number of entries of the GetRange entry below
var details=[[events[i].getTitle(),events[i].getStartTime(),events[i].getLocation(),events[i].getGuestList(),events[i].getDescription()]];
var range=sheet.getRange(row,1,1,5);
range.setValues(details);
}
问题代码1:我有#34; guestName&#34;结果: EventGuest (而不是姓名或电子邮件地址)
如果我尝试使用此代码,请执行代码测试2:
//Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)
for (var i=0;i<events.length;i++)
{
var row=i+2;
//Matching the "header=" entry above, this is the detailed row entry "details=", and must match the number of entries of the GetRange entry below
// trying to get guest name
var Nameguest = events[i].getGuestList();
var details=[[events[i].getTitle(),events[i].getStartTime(),events[i].getLocation(),**Nameguest[i].getName()**,events[i].getDescription()]];
var range=sheet.getRange(row,1,1,5);
range.setValues(details);
}
问题代码2:它只显示显示正确名称的第一行,但脚本停止并提供此错误: &#34; TypeError:无法调用方法&#34; getName& #34;未定义的。 (第xx行,文件&#34;&#34;)解散&#34;
希望这是一个简单的答案:)
提前谢谢。
答案 0 :(得分:0)
.getGuestList()
返回一个必须与外部事件循环分开循环的数组。
Nameguest[i]
正在使用仅i
应使用的events
计数器。
而不是尝试:
var names = "";
var guestList = events[i].getGuestList();
for ( var n = 0; n < guestList.length; n++ ) {
var name = guestList[n].getName();
if ( name ) {
names += name + ', ';
}
}
var details=[[events[i].getTitle(), ..., names, ...]];