2026年10月7日 星期三

[研究]Google Apps Script 核心 Service(常用模組)

[研究]Google Apps Script 核心 Service(常用模組)

2026-10-07

內建 Google 服務
https://developers.google.com/apps-script/guides/services?utm_source=chatgpt.com&hl=zh-tw

Service 主要用途 常見操作
SpreadsheetApp Google 試算表 讀寫儲存格、工作表、格式
DocumentApp Google 文件 建立/修改文件、段落、表格
FormApp Google 表單 建立表單、題目、取得回覆
DriveApp Google Drive 檔案、資料夾、搜尋、搬移
GmailApp Gmail 寄信、搜尋、讀取郵件
CalendarApp Google 日曆 建立/修改行事曆事件
ContactsApp Google 聯絡人 聯絡人資料操作
SlidesApp Google 簡報 建立/修改簡報、投影片
UrlFetchApp HTTP/REST API 呼叫外部網站、API
Utilities 通用工具 日期、編碼、JSON、Blob、Sleep
PropertiesService 儲存設定值 API Key、系統設定、使用者設定
CacheService 暫存資料 暫存 API 回傳、降低重複查詢
LockService 鎖定/同步 避免多人同時執行造成資料衝突
ScriptApp Script 本身 Trigger、執行資訊、授權
Session 使用者/執行環境 使用者 Email、時區
HtmlService Web UI HTML 網頁、Web App 前端
ContentService HTTP 回應 Web App 回傳 JSON / Text
LanguageApp 翻譯 Google Translate
MailApp 寄信 發送 Email
Charts 圖表 建立圖表物件
Jdbc 資料庫 JDBC 連接 MySQL、SQL Server 等

⭐ 最值得先學的 10 個

  • SpreadsheetApp
  • DriveApp
  • GmailApp
  • CalendarApp
  • DocumentApp
  • FormApp
  • UrlFetchApp
  • Utilities
  • PropertiesService
  • ScriptApp



Google Apps Script │ ┌──────────────┼──────────────┐ │ │ │ Google資料 外部API GAS本身 │ │ │ SpreadsheetApp UrlFetchApp ScriptApp DriveApp API PropertiesService GmailApp CacheService CalendarApp LockService DocumentApp FormApp SlidesApp

例如:操作 Google Sheet


function test() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName("工作表1"); sheet.getRange("A1").setValue("Hello GAS"); }

例如:逐行讀取 Google Sheet



function processSheetData() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues(); // 取得所有資料(二維陣列) // 跳過第一行標頭,從第二行開始迴圈 for (let i = 1; i < data.length; i++) { const name = data[i][0]; // A 欄 const email = data[i][1]; // B 欄 const status = data[i][2]; // C 欄 if (status === "待處理") { // 執行相對應的邏輯... sheet.getRange(i + 1, 3).setValue("已完成"); } } }

(完)

沒有留言:

張貼留言