重點摘要
- Apps Script 編輯器內的 Gemini 於 2026 年 11 月 12 日起全面推出,入口是 擴充功能 > Apps Script 右上角的星形圖示。
- 需要 Workspace Business Standard 或 Plus、Enterprise Standard 或 Plus,或 Google AI Pro、Ultra;香港帳戶可以使用。
- 腳本儲存後以普通程式執行,排程運行不會再用到 Gemini,但仍受 Apps Script 配額限制。
如果你的同事每逢星期一都要花 40 分鐘,把銷售試算表逐行貼進文件做週報,一個寫在 Apps Script 側邊欄的提示詞就能接手。Gemini 負責寫腳本,你負責審閱,之後由觸發器在上班前自動執行。
Gemini in Apps Script 可以替你自動化哪些工作?
它按你用文字描述的需求寫出 Apps Script:在 Gmail、日曆、試算表、文件、簡報和表單之間搬資料,加入自訂選單和定時觸發器,並解釋錯誤。每段建議程式碼你都可以逐一接受或拒絕,再儲存執行。它只處理你擁有或可編輯的專案。
Google 在 Workspace Updates 公告 中宣布全面推出,由 2026 年 11 月 12 日起分階段開放,最長需時 15 日。根據南華早報報道,Google 已於 2026 年 3 月向全體香港用戶開放 Gemini,毋須任何變通方法。
| 工具 | 能否按提示詞寫腳本 | 設定位置 | 香港可否使用 |
|---|---|---|---|
| Gemini in Apps Script | 可以,逐段接受或拒絕 | 試算表、文件、簡報或表單 > 擴充功能 > Apps Script > 星形圖示 | 可以,限合資格方案 |
| Apps Script 觸發器 | 按時間或事件執行已儲存的腳本 | 編輯器左側選單 > 觸發條件(時鐘圖示) | 可以,任何 Google 帳戶 |
開始前要知道的限制
- 根據 Google 的 Apps Script 配額頁,每次執行最長 6 分鐘;Workspace 帳戶的觸發器每日合共可運行 6 小時,個人 Gmail 帳戶只有 90 分鐘。
- 側邊欄只在編輯器語言為英文或預設時出現,而且並非所有語言都獲支援,所以提示詞建議用英文撰寫。
怎樣把緊急 Gmail 自動變成日曆跟進事項?
要求 Gemini 寫一個函式:按標籤或主旨關鍵字搜尋 Gmail,為每封符合的郵件以香港時間建立跟進事項,略過已處理的郵件,並設定每天早上自動執行的定時觸發器。這個腳本不依附任何檔案,建議在 script.new 開新專案。
情境:客戶經理把重要客戶郵件標上「緊急」,到了星期四已忘記一半。
Write a function that searches my Gmail for messages from the last 24 hours with the label [Urgent]. For each message, create a 30-minute event on my default Calendar tomorrow at [10:00] in the Asia/Hong_Kong time zone. Title: "Follow up: " plus the email subject. Description: the sender and a link to the email. Store each processed message ID so the same email never creates two events. Then add a time-driven trigger that runs the function every day at [08:00].
合格結果應包括
- 一句看得懂的 GmailApp 搜尋條件,例如標籤加上 newer_than:1d。
- 已處理的郵件編號存放在指令碼屬性,而不是藏在某個工作表。
怎樣把試算表資料自動整理成每週文件報告?
打開試算表,進入 擴充功能 > Apps Script,要求 Gemini 篩選最近七天的資料、按分組欄位加總,建立一份有標題、表格和一句摘要的新文件,存入指定資料夾,再加一個自訂選單,讓團隊任何人都能一鍵產生報告。
情境:每逢星期一由同事從兩千行試算表人手整理的銷售週報。
In this spreadsheet, read the sheet named [Sales]. Keep rows where column [Date] is within the last 7 days, using the Asia/Hong_Kong time zone. Total [Orders] and [Revenue] by [Region]. Create a new Google Doc titled "Weekly report " plus today's date (YYYY-MM-DD) containing: a heading, a table with columns Region, Orders, Revenue (HK$, no decimals), and one sentence naming the region with the largest change against the previous 7 days. Save the Doc in the Drive folder with ID [folder ID]. Add a custom menu "Reports > Build weekly report" that runs the function.
合格結果應包括
- 按標題名稱找欄位,而不是寫死欄位字母,插入新欄也不會出錯。
- 資料夾編號與你提供的完全一致。Google 指出生成的程式碼可能刪去網址,所以編號要完整貼上。
怎樣把 Google 表單回覆自動分派給負責同事?
把腳本綁定在表單的回覆試算表,要求一個可安裝的提交表單觸發器:讀取其中一個答案,在另一個工作表查出負責人,再把整份回覆電郵給對方。對照表放在試算表內,日後更換負責人便毋須改程式碼。
情境:公司內部的 IT 或行政申請表,回覆全部堆在一個共用信箱無人處理。
This spreadsheet receives responses from a Google Form. When a new response arrives, read the answer to [Which department?]. Look up that department in the sheet [Owners] (column A department, column B email) and send that owner an email with subject "New request: " plus the [Request title] answer, listing every question and answer from the response. If no owner is found, send it to [ops@yourcompany.com]. Use an installable on-form-submit trigger and write "Sent to " plus the email address in a new column [Routed to].
合格結果應包括
- 使用可安裝觸發器,因為簡單觸發器不能發送電郵。
- 設有後備收件地址,確保沒有申請被遺漏。
怎樣清理試算表內雜亂的聯絡人名單?
要求 Gemini 把清理後的資料寫到新工作表,原始資料一律不改,並逐條寫明規則:刪除空格、姓名大小寫、香港電話格式、無效號碼的處理方法,以及重複資料保留哪一行。只寫「幫我整理一下」,得到的程式碼便無法預測。
情境:活動報名表有 1,200 個登記,電話號碼有五種不同寫法。
Read the sheet [Leads]. For each row: trim spaces in every cell; write [Name] in Proper Case; convert [Phone] to the format "+852 XXXX XXXX" after removing spaces, dashes and any existing 852 or +852 prefix; if the result is not exactly 8 digits, keep the original value and write "Check" in a new column [Phone check]. Remove rows with the same [Email], keeping the row with the latest [Timestamp]. Write the result to a new sheet [Leads_clean] and do not change [Leads]. Log how many rows were removed and how many phones were flagged.
合格結果應包括
- 用 getValues 和 setValues 一次讀寫整批資料,1,200 行的處理可穩妥地在 6 分鐘上限內完成。
- 執行記錄中的數字與新工作表一致。
腳本能執行但結果錯誤,怎樣修正?
若出現執行錯誤,在執行記錄按「Fix with Gemini」,再審閱它提出的修改。若腳本順利完成但數字不對,就寫清楚預期結果、實際結果和函式名稱。Google 的說明文件指出,這類具體描述能得到更準確的修正。
情境:週報顯示上週零張訂單,但試算表內明明有超過 100 行當週資料。
The function [buildWeeklyReport] runs without errors but reports [0 orders] for last week. Expected: about [120 orders]. Check the date filter and whether the script and spreadsheet time zones both use Asia/Hong_Kong. Explain the cause in plain language first, then propose the smallest change that fixes it. Do not rewrite other functions.
合格結果應包括
- 一個你能自行驗證的原因,例如日期以文字儲存,或專案設定用了 UTC 時區。
- 只改少量程式碼,而不是整份重寫。
怎樣把這些提示詞改成適合自己的版本?
把每個方括號換成真實的工作表名稱、欄位標題、時間和編號,一個提示詞只做一件事,並加上你在意的上限,例如最多發送多少封電郵。然後先在檔案副本上測試,細閱授權畫面,手動執行無誤後才開啟觸發器。
- 提供參考檔案: 在側邊欄輸入 @ 加上文件或試算表網址,讓 Gemini 以該檔案為依據;目前不支援檔案選擇器。
- 每次執行的成本: Gemini 已包含在合資格方案內,儲存後的腳本以普通程式執行,每日排程不會產生額外 AI 費用,限制只在於上述 Apps Script 配額。
最後驗證日期:2026 年 12 月 2 日,依據 Google 的 Gemini in Apps Script 說明文件 及配額頁面。
先寫好提示詞,再讀懂程式碼
Gemini 解決了 Apps Script 最難的第一步,但腳本始終以你的權限執行。寫明工作表、時區和上限,逐段接受程式碼,並先在副本測試。
懂AI,更懂你 UD相伴,AI不冷
不想自己搭建和維護這些腳本?
工作表一改、負責人一走、授權一過期,觸發器就會出錯。如果你不想自己搭和維護這套流程,可以交給 UD 按職位部署和維運的 AI 員工。由免費 AI 員工配置評估到日常運作,我們手把手帶你完成每一步。
常見問題
香港可以使用 Gemini in Apps Script 嗎?
可以。Gemini 自 2026 年 3 月起向香港用戶開放;只要管理員已開啟 Gemini,Workspace Business Standard 或 Plus、Enterprise Standard 或 Plus,以及 Google AI Pro 或 Ultra 用戶都能使用側邊欄。
排程執行的腳本會消耗 Gemini 用量嗎?
不會。Gemini 只協助撰寫和修正程式碼,儲存後的腳本以普通 Apps Script 執行,只受 Google 配額限制,例如 Workspace 帳戶的觸發器每日合共可運行 6 小時。
公司可以禁止員工使用這項功能嗎?
可以。管理員可透過 Apps Script 服務設定及 Workspace 生成式 AI 存取控制,按機構單位或群組開關功能,並在雲端硬碟及 OAuth 稽核記錄查看腳本活動。