2013-04-23 53 views
0

我發現這個腳本(由Jonathon發佈),並且需要修改它以提供用戶名。如何使用getGuestList獲取名稱而不是電子郵件地址?

當我嘗試獲取客人姓名(使用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); 
} 

回答

1

您需要遍歷由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; 
    }) 
); 
} 
相關問題