填入團隊休假日曆
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
程式設計程度:初學者
時間:15 分鐘
專案類型:使用時間觸發條件的自動化作業
目標
- 瞭解解決方案的功能。
- 瞭解解決方案中的 Apps Script 服務功能。
- 設定指令碼。
- 執行指令碼。
認識這項解決方案
共用休假日曆是協助團隊協作的絕佳工具,可讓任何人一目瞭然誰不在辦公室。這項解決方案可讓您查看同事何時不在辦公室,不必手動輸入。

運作方式
這項解決方案會根據 Google 群組中每個人的日曆,填入共用的假期日曆。使用者預約休假時,會在個人 Google 日曆中新增活動,並使用「休假」或「不在辦公室」等關鍵字。
每小時,指令碼會掃描群組成員的日曆,並將適當的活動同步至共用日曆。您可以變更指令碼掃描新事件的頻率。
這項解決方案只會存取同事透過隱私權設定向您顯示的日曆活動。
Apps Script 服務
這項解決方案會使用下列服務:
必要條件
如要使用這個範例,您必須符合下列先決條件:
- Google 帳戶 (Google Workspace 帳戶可能需要管理員核准)。
- 可連上網際網路的網路瀏覽器。
設定指令碼
建立團隊休假日曆
- 開啟 Google 日曆。
- 建立名為「團隊假期」的新日曆。
- 在日曆設定的「整合日曆」下方,複製「日曆 ID」。
建立 Apps Script 專案
- 按一下下列按鈕,開啟「Vacation Calendar」Apps Script 專案。
開啟專案
- 按一下「總覽」info_outline。
- 在總覽頁面中,按一下「建立副本」圖示
。
- 在複製的 Apps Script 專案中,將變數
TEAM_CALENDAR_ID
設為您先前建立的日曆 ID。
- 將變數
GROUP_EMAIL
設為包含團隊成員的 Google 群組電子郵件地址。
- 按一下「服務」旁的「新增服務」圖示 add。
- 選取「Google Calendar API」,然後按一下「新增」。
執行指令碼
- 在複製的 Apps Script 專案中,從函式下拉式選單選取「設定」。
- 按一下「執行」。
出現提示訊息時,請授權執行指令碼。如果 OAuth 同意畫面顯示「這個應用程式未經驗證」警告,請依序選取「進階」>「前往『{專案名稱}』(不安全)」,繼續操作。
完成後,請返回日曆,確認「Team Vacations」日曆已填入活動。
檢查程式碼
如要查看這項解決方案的 Apps Script 程式碼,請按一下下方的「查看原始碼」:
修正規則
您可以視需要編輯團隊休假日曆自動化功能。以下是修改觸發條件的選用變更。
變更指令碼掃描新事件的頻率
如要變更指令碼的執行頻率,請按照下列步驟操作:
- 在 Apps Script 專案中,按一下「觸發條件」alarm。
- 按一下觸發條件旁的「編輯觸發條件」圖示 edit。
- 選取變更內容,然後按一下「儲存」。
貢獻者
這個範例由 Google 維護,並由 Google 開發人員專家協助。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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,[]]