本文介绍了如何使用getGuestList获取名称,而不是电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了此脚本(由Jonathon发布),并且需要对其进行修改以提供用户名.

I've found this script (posted by Jonathon), and need to modify it to provide user names.

当我尝试获取来宾姓名(使用getGuestList())时,它将在我的电子表格中返回EventGuest.

When I try to get the guest names (using getGuestList()) it returns EventGuest in my spreadsheet.

如何将访客姓名(而非电子邮件)输入电子表格?

How can I get the guest names (not emails) into the spreadsheet?

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()此处记录.您应该验证名称是否为空,并且在这种情况下也许可以接受电子邮件-我会留给您.

You need to iterate over the guests returned by Event.getGuestList(), and retrieve each name with EventGuest.getName(), documented here. You should validate that the name isn't blank, and perhaps settle for the email in that case - I'll leave that to you.

这是您的功能将如何更改:

Here's how your function would change:

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;
    })
  );
 }

这篇关于如何使用getGuestList获取名称,而不是电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:15