我已经找到了这个脚本(由Jonathon发布),需要对其进行修改以提供用户名。
[当我尝试使用getGuestList()
获取来宾名称时,它将在我的电子表格中返回EventGuest。
如何将访客姓名(而非电子邮件)输入电子表格?
function caltest3(){
var ss = SpreadsheetApp.openById( 'spreadsheetId' ),
sheet = ss.getSheetByName( 'sheetName' ),
cals = ['id1', 'id2', 'id3'], c, cal, calName,
start = new Date( 'whenever' ), end = new Date( 'whenever' ),
events, i, details,
eventslog = [], e,
rows = [], range;
for (c = 0; c < cals.length; c += 1) {
cal = CalendarApp.getCalendarById(cals[c]);
calName = cal.getTitle();
events = cal.getEvents(start, end);
// add the events of the current calendar to the array of all events
eventslog = eventslog.concat(
events.map(function(event) {
return {
time: new Date(event.getStartTime()).getTime(), // sort by this
details: [
event.getTitle(),
event.getStartTime(),
event.getEndTime(),
event.getDescription(),
event.getLocation(),
calName // change calendar info position in array to suit
]
};
})
);
}
// sort array of event so date order can be either way by reversing a & b
eventslog.sort(function(a, b) { return a.time - b.time; });
rows = eventslog.map(function(entry) { return entry.details; });
range = sheet.getRange(2, 1, rows.length, 6);
range.setValues(rows);
}
您需要遍历Event.getGuestList()
返回的来宾,并使用EventGuest.getName()
,documented here检索每个名称。您应该验证名称是否为空,并且在这种情况下也许可以接受电子邮件-我会留给您。
这是您的功能将如何更改:
function caltest3(){
var ss = SpreadsheetApp.openById( 'spreadsheetId' ),
sheet = ss.getSheetByName( 'sheetName' ),
cals = ['id1', 'id2', 'id3'], c, cal, calName,
start = new Date( 'whenever' ), end = new Date( 'whenever' ),
events, i, details,
eventslog = [], e,
rows = [], range;
for (c = 0; c < cals.length; c += 1) {
cal = CalendarApp.getCalendarById(cals[c]);
calName = cal.getTitle();
events = cal.getEvents(start, end);
// add the events of the current calendar to the array of all events
eventslog = eventslog.concat(
events.map(function(event) {
var deets = {
time: new Date(event.getStartTime()).getTime(), // sort by this
details: [
event.getTitle(),
event.getStartTime(),
event.getEndTime(),
event.getDescription(),
event.getLocation(),
calName // change calendar info position in array to suit
]
};
var guestList = event.getGuestList();
event.guests = [];
for (var i in guestList) {
event.guests.push(guestList[i].getName());
}
deets.guests = guestList;
return deets;
})
);
}
我是这个菜鸟。谁能帮我?我有同样的问题,但无法解决。我想要给我的客人发送电子邮件或姓名。不,我只是获得EventGuest。没有数字或名称。
function getEvents(){
var ss = SpreadsheetApp.getActiveSpreadsheet()。getActiveSheet();var cal = CalendarApp.getCalendarById(“我的日历ID在这里正常”);var events = cal.getEvents(new Date(“ 06/01/2020 12:00 AM”),new Date(“ 06/30/2030 12:00 AM”));
var lr = ss.getLastRow();ss.getRange(2,1,lr-1,6).clearContent();
for(var i = 0; i
var title = events[i].getTitle();
var sd = events[i].getStartTime();
var ed = events[i].getEndTime();
var loc = events[i].getLocation();
var des = events[i].getDescription();
var guest = events[i].getGuestList();
ss.getRange(i+2, 1).setValue(title);
ss.getRange(i+2, 2).setValue(sd);
ss.getRange(i+2, 2).setNumberFormat("dd/mm/yyyy /hh:mm");
ss.getRange(i+2, 3).setValue(ed);
ss.getRange(i+2, 3).setNumberFormat("dd/mm/yyyy /hh:mm");
ss.getRange(i+2, 4).setValue(loc);
ss.getRange(i+2, 5).setValue(des);
ss.getRange(i+2, 6).setValue(guest);
}}