填充团队假期日历
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
编码水平:初级
时长:15 分钟
项目类型:使用定时触发器实现的自动化
目标
- 了解解决方案的功能。
- 了解 Apps 脚本服务在解决方案中的作用。
- 设置脚本。
- 运行脚本。
关于此解决方案
共享休假日历是帮助团队协作的绝佳工具;任何人都可以一目了然地确定谁不在办公室。借助此解决方案,您可以查看同事的外出时间,无需手动输入任何内容。

运作方式
此解决方案会根据 Google 群组中每个人的个人日历填充共享的假期日历。当有人安排休假时,他们会使用“休假”或“不在办公室”等关键字向自己的个人 Google 日历添加活动。
该脚本每小时扫描一次群组中成员的日历,并将合适的活动同步到共享日历。您可以更改脚本扫描新事件的频率。
此解决方案仅访问您的同事通过隐私设置向您公开的日历活动。
Apps 脚本服务
此解决方案使用以下服务:
前提条件
如需使用此示例,您需要满足以下前提条件:
- Google 账号(Google Workspace 账号可能需要管理员批准)。
- 可访问互联网的网络浏览器。
设置脚本
创建团队休假日历
- 打开 Google 日历。
- 创建名为“团队休假”的新日历。
- 在日历的设置中,找到集成日历,然后复制日历 ID。
创建 Apps 脚本项目
- 点击以下按钮打开休假日历 Apps 脚本项目。
打开项目
- 点击概览 info_outline。
- 在概览页面上,点击“复制”图标
。
- 在复制的 Apps 脚本项目中,将变量
TEAM_CALENDAR_ID
设置为您之前创建的日历的 ID。
- 将变量
GROUP_EMAIL
设置为包含团队成员的 Google 群组的电子邮件地址。
- 点击服务旁边的“添加服务”图标 add。
- 选择 Google Calendar API,然后点击添加。
运行脚本
- 在复制的 Apps 脚本项目中,从函数下拉菜单中选择 setup。
- 点击运行。
根据提示为脚本授权。
如果 OAuth 权限请求页面显示警告此应用未经过验证,请继续操作,依次选择高级 >
前往“{项目名称}”(不安全)。
完成后,返回日历,确认“团队休假”日历已填充活动。
查看代码
如需查看此解决方案的 Apps 脚本代码,请点击下方的查看源代码:
修改
您可以根据需要随意修改团队休假日历自动化。以下是用于修改触发器的可选更改。
更改脚本扫描新事件的频率
如需更改脚本的运行频率,请按以下步骤操作:
- 在 Apps 脚本项目中,点击触发器图标 alarm。
- 点击触发器旁边的“修改触发器”图标 edit。
- 选择更改,然后点击保存。
贡献者
此示例由 Google 在 Google 开发者专家的帮助下维护。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThis solution automatically syncs employee time-off entries to a shared calendar using keywords like "Vacation" or "Out of Office".\u003c/p\u003e\n"],["\u003cp\u003eIt leverages Google Calendar and Groups services to identify team members and scan their calendars for relevant events.\u003c/p\u003e\n"],["\u003cp\u003eThe script runs hourly and imports events into the shared calendar, respecting user privacy settings.\u003c/p\u003e\n"],["\u003cp\u003eUsers need a Google Account and a shared 'Team Vacation' Google Calendar to use this solution.\u003c/p\u003e\n"],["\u003cp\u003eThe script can be easily customized to change the trigger frequency or keywords used to identify time-off events.\u003c/p\u003e\n"]]],["This solution automates the creation of a shared team vacation calendar by syncing events from individual Google Calendars. It scans members of a specified Google Group and populates the team calendar with events containing keywords like \"vacation.\" The script utilizes the Groups and Calendar advanced services to identify group members and access their calendar events. The script is set up with an hourly time-driven trigger to scan for events automatically, but the trigger can be modified. Users need to create both a Team calendar and a Google Group.\n"],null,[]]