使用此类代码将Google日历提取到工作表中(此代码已从其他来源实施:
function cal_to_gsht(){
var ss = SpreadsheetApp.openById( ' id_gsheet ' ), // Id is set to file 'CAL-to-gsheets' in LPRMF dir
sheet = ss.getActiveSheet(),
cals = [' cal1 ', ' cal2 '], c, cal, calName,
//?? cals = getAllCalendars(),
today = new Date(),
start = new Date( today ), end = new Date( 'Dec 31, 2019' ),
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: [
calName, // calNAme-change calendar info position in array to adjust
event.getTitle(),
event.getDescription(),
event.getLocation(),
event.getStartTime(),
event.getEndTime(),
event.addGuest()
// event.getGuestList()
// event.getGuestByEmail(0)
]
};
})
);
}
// 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, 7); // no. of event.details ; increase if more event.get
range.setValues(rows);
}
如何添加到事件。另一个记录将是来宾姓名和/或电子邮件。
请告知
此后...厌倦了通过getEmail()提取电子邮件,但没有成功:
function(event) {
var guestList=event.getGuestList();
var email1=guestList[0]; // how to get EMAIL out of it !
var email2=guestList[1];
return {
time: new Date(event.getStartTime()).getTime(),
details: [
calName,
event.getTitle(),
event.getDescription(),
event.getLocation(),
event.getStartTime(),
event.getEndTime(),
email1,
email2
]
};
})
getEmail()如何工作?
答案 0 :(得分:0)
找到解决方案,对数组几乎不需要任何高级方法,将它们映射并再次连接两个:
function(event) {
return {
time: new Date(event.getStartTime()).getTime(),
details: [
calName,
event.getTitle(),
event.getDescription(),
event.getLocation(),
event.getStartTime(),
event.getEndTime(),
event.getGuestList().map(function(x) {return x.getEmail();}).join(',')
]
};