0

我找到了这个脚本(由 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);
}
4

1 回答 1

1

您需要遍历返回的客人Event.getGuestList(),并检索每个名称EventGuest.getName()记录在这里。您应该验证该名称是否为空白,并且在这种情况下可能会选择电子邮件 - 我将把它留给您。

以下是您的功能将如何改变:

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;
    })
  );
 }
于 2013-05-12T14:53:58.960 回答