【问题标题】:CalendarEvent color日历事件颜色
【发布时间】:2013-10-04 20:02:15
【问题描述】:

当我手动创建日历事件时,可以为事件赋予特殊颜色。 如何使用脚本访问/更改此颜色?搜索了所有文档,但仅在日历级别找到颜色,而不是在事件级别。

【问题讨论】:

    标签: colors google-apps-script google-calendar-api


    【解决方案1】:

    【讨论】:

    • 这是指日历 API,而不是 GAS!你不能“开箱即用”使用它
    【解决方案2】:

    新的高级日历服务现在允许您执行此操作。查看“创建事件”标题下的示例代码:

    https://developers.google.com/apps-script/advanced/calendar

    我会将它粘贴在下面以防更改帮助页面:

       function createEvent() {
      var calendarId = 'primary';
      var start = getRelativeDate(1, 12);
      var end = getRelativeDate(1, 13);
      var event = {
        summary: 'Lunch Meeting',
        location: 'The Deli',
        description: 'To discuss our plans for the presentation next week.',
        start: {
          dateTime: start.toISOString()
        },
        end: {
          dateTime: end.toISOString()
        },
        attendees: [
          {email: 'alice@example.com'},
          {email: 'bob@example.com'}
        ],
        // Red background. Use Calendar.Colors.get() for the full list.
        colorId: 11
      };
      event = Calendar.Events.insert(event, calendarId);
      Logger.log('Event ID: ' + event.getId());
    }
    
    /**
     * Helper function to get a new Date object relative to the current date.
     * @param {number} daysOffset The number of days in the future for the new date.
     * @param {number} hour The hour of the day for the new date, in the time zone
     *     of the script.
     * @return {Date} The new date.
     */
    function getRelativeDate(daysOffset, hour) {
      var date = new Date();
      date.setDate(date.getDate() + daysOffset);
      date.setHours(hour);
      date.setMinutes(0);
      date.setSeconds(0);
      date.setMilliseconds(0);
      return date;
    }
    

    【讨论】:

      【解决方案3】:

      另一个答案是指您最终可以访问的日历 API,但它不是 GAS 中可用的标准日历方法的一部分。

      您可以通过使用 Romain Vialard(gas 顶级贡献者)开发的库来简化您的生活,该库可在 his website 以及广泛使用它的 application I wrote 上获得

      edit : 还有an enhancement request on this on the issue tracker 是我不久前提出的,请随意star。

      【讨论】:

        猜你喜欢
        • 2016-03-16
        • 2015-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多