Use cases

Reviewed 2026-07-22

Google Sheets 自动化

在为团队启用 Google Sheets 自动化之前进行测试的审核模式。

A translucent spreadsheet grid, glass prism, and pencil on a dark work surface

How this page was reviewed

在包含 Orders 工作表和 Status 列的独立 Apps Script 项目中测试。授权前请检查所需权限。

01

安全实现

从工作表副本开始,明确预期结果,并在添加触发器前手动运行函数。

02

失败情况

缺少工作表名称、列被移动、授权不足和配额都可能停止自动化。记录失败并让操作具备幂等性。

Implementation note

Tested example

function markPendingOrders() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Orders');
  if (!sheet) throw new Error('Orders sheet not found');
  const values = sheet.getDataRange().getValues();
  values.slice(1).forEach((row, index) => {
    if (row[2] === 'Pending') sheet.getRange(index + 2, 3).setValue('Ready');
  });
}
Required scope
https://www.googleapis.com/auth/spreadsheets.currentonly
Expected output
Orders 的 C 列中每个 Pending 值都会变为 Ready。
Watch for
如果缺少 Orders,函数会报错。使用验证保护生产运行,并避免在大型表格中逐单元格写入。

Official sources

Read the original documentation before changing a production workflow.