Spreadsheet Automation
Overview
Google Sheets isn't just for budgets and lists. With the right formulas, Apps Script, and integrations, it becomes a database, CRM, project tracker, analytics dashboard, and workflow engine — all in one free tool. This playbook shows you how to build production-grade systems in Sheets that replace $50-500/month SaaS tools.
Step 1: Identify What to Automate in Sheets
Not every workflow belongs in Sheets. Here's when Sheets is the right tool.
Good use cases for Sheets automation:
- - Data collection from multiple sources (form responses, API data, manual input) → centralize in one place
- Lightweight databases (customer lists, inventory, project tracker) → under 10K rows, basic relationships
- Dashboards and reporting (pull data from other tools, visualize, share)
- Workflow triggers (when row added/updated → send email, create task, update another sheet)
- Data transformation (clean, format, enrich data from messy sources)
Bad use cases (use a real database or tool instead):
- - Heavy computation (millions of rows, complex queries) → use BigQuery, Airtable, or SQL database
- Real-time collaboration with 10+ concurrent users → use Airtable, Notion, or dedicated project management tool
- Mission-critical data that can't afford accidental deletion → use a real database with backups and version control
- Complex relational data (many-to-many relationships) → use Airtable or proper database
Audit your current manual work (10 min):
- 1. List tasks you do in Sheets manually (copy/paste, data entry, formatting, updating other sheets)
- Which tasks are repetitive? (daily, weekly, triggered by an event)
- Which tasks take 5+ minutes each time?
- Which tasks have clear logic? ("If this, then that")
Low-hanging fruit checklist:
- - [ ] Auto-populate cells based on other cells (formulas)
- [ ] Pull data from external sources (APIs, other sheets, web scraping)
- [ ] Auto-format or clean data (remove duplicates, standardize dates, extract values)
- [ ] Send notifications when conditions are met (email alerts, Slack messages)
- [ ] Create charts or dashboards that update automatically
- [ ] Sync data between Sheets and other tools (CRM, project management, accounting)
Step 2: Master Advanced Formulas (No Code Required)
Most Sheets automation starts here. Master these formulas and you can build 80% of what you need without Apps Script.
Core Formula Reference
QUERY (SQL-like queries in Sheets):
=QUERY(A1:D100, "SELECT A, B, C WHERE D > 1000 ORDER BY C DESC")
- - Use for: Filter, sort, group, and summarize data
- Syntax: INLINECODE0
- Example: Pull all customers with orders > $1,000, sorted by date
IMPORTRANGE (pull data from other sheets):
=IMPORTRANGE("spreadsheet_url", "Sheet1!A1:D100")
- - Use for: Centralize data from multiple sheets into one master sheet
- Setup: First time, you need to approve access (click "Allow access" when prompted)
- Example: Pull sales data from regional team sheets into one master dashboard
ARRAYFORMULA (apply formula to entire column):
=ARRAYFORMULA(IF(A2:A="",,B2:B*C2:C))
- - Use for: Auto-calculate for all rows (no dragging formulas down)
- Example: Auto-multiply quantity × price for every new row added
VLOOKUP / XLOOKUP (lookup values from another table):
=VLOOKUP(A2, Sheet2!A:B, 2, FALSE)
- - Use for: Match and pull related data (e.g., customer name → pull their email)
- XLOOKUP (newer): More flexible, can search left-to-right or right-to-left
FILTER (dynamic filtering):
=FILTER(A2:D100, D2:D100>1000, C2:C100="Active")
- - Use for: Show only rows that meet criteria (updates automatically when data changes)
- Example: Show only active customers with revenue > $1,000
UNIQUE (remove duplicates):
=UNIQUE(A2:A100)
- - Use for: Extract unique values from a list (auto-updates when source changes)
REGEXEXTRACT (extract patterns from text):
=REGEXEXTRACT(A2, "[0-9]{3}-[0-9]{3}-[0-9]{4}")
- - Use for: Pull phone numbers, emails, URLs, or any pattern from messy text
- Example: Extract domain from email addresses
IMPORTXML / IMPORTHTML (scrape web data):
=IMPORTXML("https://example.com", "//h1")
- - Use for: Pull live data from websites (prices, headlines, tables)
- Example: Track competitor pricing automatically
Step 3: Build Multi-Sheet Systems
Single-sheet solutions are limited. Real power comes from connecting multiple sheets into a system.
System architecture pattern:
CODEBLOCK8
Example: Simple CRM in Sheets
Sheet 1: Lead Entry Form
- - Columns: Name, Email, Company, Source, Date Added
- Use: Google Form → auto-populates this sheet
- Validation: Email format check, required fields
Sheet 2: Master Lead Database
- - Pulls from Sheet 1 using
IMPORTRANGE or direct reference - Adds enrichment: Status (New/Contacted/Qualified/Closed), Last Contact Date, Notes
- Formula example:
=IF(ISBLANK(D2), "New", D2) (auto-set status to "New" if empty)
Sheet 3: Dashboard
- - Total leads: INLINECODE3
- Leads this week: INLINECODE4
- Conversion rate: INLINECODE5
- Chart: Leads by source (pie chart)
Sheet 4: Weekly Report
- - Formula: INLINECODE6
- Auto-pull this week's leads for review meeting
Key principles:
- - One sheet = one purpose (don't mix input, storage, and display)
- Use formulas to connect sheets (avoid manual copy/paste)
- Protect important sheets (prevent accidental edits)
Step 4: Learn Apps Script Basics (Google's JavaScript for Sheets)
Apps Script lets you do things formulas can't: send emails, make API calls, create custom menus, run code on a schedule.
When to use Apps Script:
- - Formulas can't do it (sending emails, hitting APIs, complex logic)
- You need automation to run on a schedule (every hour, daily, weekly)
- You want custom functions or menu items
How to access Apps Script:
- 1. Open your Google Sheet
- Extensions → Apps Script
- Write code in the editor
Example 1: Send Email Alert When New Row Added
CODEBLOCK9
How to set up:
- 1. Paste code into Apps Script editor
- Save (Ctrl/Cmd + S)
- Set up trigger: Triggers (clock icon) → Add Trigger →
onEdit → From spreadsheet → On edit → Save - Authorize permissions when prompted
Example 2: Fetch Data from API and Write to Sheet
CODEBLOCK10
How to set up:
- 1. Paste code, replace
url and INLINECODE9 - Run once manually to test (click Run button)
- Set up time-based trigger: Triggers → Add Trigger →
fetchAPIData → Time-driven → Hour timer → Every hour
Example 3: Auto-Archive Old Rows
CODEBLOCK11
Common Apps Script patterns:
- - Get data: INLINECODE11
- Write data: INLINECODE12
- Append row: INLINECODE13
- Send email: INLINECODE14
- Make HTTP request: INLINECODE15
- Get current date: INLINECODE16
Apps Script resources:
- - Official docs: https://developers.google.com/apps-script
- ChatGPT or Claude: "Write Apps Script to [do X]" → copy/paste/test
Step 5: Connect Sheets to Other Tools (Zapier, Make, n8n)
Sheets becomes 10x more powerful when integrated with other tools.
Integration strategies:
Strategy 1: Sheets as Database (write-only)
Use case: Collect data from forms, webhooks, or other tools → write to Sheets for storage
Example workflow (Zapier/Make):
CODEBLOCK12
Example workflow (Webhook → Sheets):
CODEBLOCK13
Strategy 2: Sheets as Trigger (read-only)
Use case: When row added/updated in Sheets → trigger action elsewhere
Example workflow:
CODEBLOCK14
Strategy 3: Sheets as Middleman (read + write)
Use case: Sheets pulls data from Tool A, processes it, pushes to Tool B
Example workflow (sync CRM to email tool):
CODEBLOCK15
Best tools for Sheets integration:
- - Zapier: Easiest, widest app support, $20-50/month
- Make (Integromat): More powerful, visual, $9-30/month
- n8n: Self-hosted, unlimited, free (or $20/month hosted)
Common integrations:
- - Google Forms → Sheets (native, no tool needed)
- Sheets → Gmail (send emails based on Sheet data)
- Sheets → Slack (post updates to Slack when Sheet changes)
- Sheets ↔ Airtable (sync data both ways)
- API → Sheets (pull data from any API into Sheets)
Step 6: Real-World Automation Examples
Example 1: Automated Invoice Tracker
Problem: Manually tracking invoices sent, paid, and overdue
Solution:
Sheet 1: Invoice Log
- - Columns: Invoice #, Client, Amount, Date Sent, Due Date, Status, Days Overdue
Formula magic:
CODEBLOCK16
Apps Script (run daily):
CODEBLOCK17
Trigger: Time-driven, daily at 9am
Example 2: Lead Scoring System
Problem: Manually qualifying leads based on fit
Solution:
Sheet 1: Lead Data
- - Columns: Name, Company Size, Industry, Budget, Urgency, Score, Priority
Formula scoring:
CODEBLOCK18
Automation (Zapier):
TRIGGER: New row in Google Sheets
CONDITION: Priority = "Hot"
ACTION 1: Add to Pipedrive as high-priority deal
ACTION 2: Send Slack notification to sales team
Example 3: Content Calendar + Auto-Publishing
Problem: Manually tracking and scheduling social posts
Solution:
Sheet 1: Content Calendar
- - Columns: Date, Platform, Post Text, Image URL, Status
Apps Script (run hourly):
function publishScheduledPosts() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Content Calendar");
var data = sheet.getDataRange().getValues();
var now = new Date();
for (var i = 1; i < data.length; i++) {
var scheduleDate = new Date(data[i][0]);
var status = data[i][4];
// If scheduled for now or past, and not yet published
if (scheduleDate <= now && status === "Scheduled") {
var platform = data[i][1];
var text = data[i][2];
// Call API to post (Twitter, LinkedIn, etc.)
postToAPI(platform, text);
// Mark as published
sheet.getRange(i+1, 5).setValue("Published");
}
}
}
function postToAPI(platform, text) {
// Example: Twitter API call
var url = "https://api.twitter.com/2/tweets";
var payload = JSON.stringify({"text": text});
var options = {
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_TWITTER_TOKEN",
"Content-Type": "application/json"
},
"payload": payload
};
UrlFetchApp.fetch(url, options);
}
Step 7: Performance and Scalability
When Sheets starts to slow down:
Problem: Sheet with 10K+ rows, complex formulas → slow to load/edit
Solutions:
- 1. Use QUERY instead of FILTER + SORT: More efficient
- Limit ARRAYFORMULA range:
A2:A1000 instead of A:A (entire column) - Use static values instead of formulas where possible: Copy → Paste Values
- Split into multiple sheets: Archive old data to separate sheet
- Use Importrange sparingly: Each call adds load time
- Cache data with Apps Script: Pull external data once, store it, refresh periodically instead of live formulas
When to migrate away from Sheets:
- - 50K+ rows → Use Airtable or BigQuery
- Real-time collaboration with 20+ users → Use Airtable or Notion
- Complex relational queries → Use Airtable or SQL database
- Mission-critical data → Use proper database with backups
Backup strategy:
- - Version history: File → Version history (Google auto-saves, you can restore)
- Automated exports: Apps Script to export to Google Drive weekly
- Download copies: File → Download → Excel or CSV (manual backup)
Step 8: Spreadsheet Automation ROI
ROI calculation:
CODEBLOCK21
Example:
CODEBLOCK22
Rule: If it saves 5+ hours/month, automate it.
Spreadsheet Automation Mistakes to Avoid
- - Building everything in one massive sheet. Break into multiple sheets (input, database, dashboard, exports).
- Not protecting important sheets. One accidental delete can wipe out your system. Use Data → Protect sheets and ranges.
- Overusing volatile formulas.
NOW(), TODAY(), RAND() recalculate constantly and slow down sheets. Use sparingly. - Not documenting your formulas. Add comments (right-click cell → Insert comment) to explain complex formulas.
- Forgetting to set up triggers for Apps Script. Code won't run unless you set up a trigger (onEdit, time-driven, etc.).
- Not testing automations before going live. Test with dummy data first. A broken automation that sends 100 emails is a disaster.
- Using Sheets for things it's not meant for. If you hit 20K+ rows, move to a real database.
电子表格自动化
概述
Google Sheets 不仅仅用于预算和清单。借助正确的公式、Apps Script 和集成,它可以成为数据库、CRM、项目追踪器、分析仪表盘和工作流引擎——所有这些都集成在一个免费工具中。本指南将向您展示如何在 Sheets 中构建可替代每月50-500美元SaaS工具的生产级系统。
第一步:确定在 Sheets 中自动化什么
并非每个工作流都适合在 Sheets 中处理。以下是 Sheets 作为正确工具的场景。
适合 Sheets 自动化的场景:
- - 从多个来源收集数据(表单回复、API数据、手动输入)→ 集中到一个地方
- 轻量级数据库(客户列表、库存、项目追踪器)→ 少于10K行,基本关系
- 仪表盘和报告(从其他工具拉取数据、可视化、分享)
- 工作流触发器(当行添加/更新时 → 发送邮件、创建任务、更新另一个表格)
- 数据转换(清理、格式化、丰富来自杂乱来源的数据)
不适合的场景(改用真正的数据库或工具):
- - 大量计算(数百万行、复杂查询)→ 使用 BigQuery、Airtable 或 SQL 数据库
- 与10+并发用户实时协作 → 使用 Airtable、Notion 或专用项目管理工具
- 不能承受意外删除的关键数据 → 使用带备份和版本控制的真正数据库
- 复杂关系数据(多对多关系)→ 使用 Airtable 或合适的数据库
审计您当前的手动工作(10分钟):
- 1. 列出您在 Sheets 中手动执行的任务(复制/粘贴、数据输入、格式化、更新其他表格)
- 哪些任务是重复性的?(每日、每周、由事件触发)
- 哪些任务每次需要5分钟以上?
- 哪些任务有清晰的逻辑?(如果这样,则那样)
低挂果实检查清单:
- - [ ] 基于其他单元格自动填充单元格(公式)
- [ ] 从外部来源拉取数据(API、其他表格、网页抓取)
- [ ] 自动格式化或清理数据(删除重复项、标准化日期、提取值)
- [ ] 当条件满足时发送通知(邮件提醒、Slack消息)
- [ ] 创建自动更新的图表或仪表盘
- [ ] 在 Sheets 和其他工具之间同步数据(CRM、项目管理、会计)
第二步:掌握高级公式(无需代码)
大多数 Sheets 自动化从这里开始。掌握这些公式,您可以在不使用 Apps Script 的情况下构建80%所需功能。
核心公式参考
QUERY(类似SQL的查询):
=QUERY(A1:D100, SELECT A, B, C WHERE D > 1000 ORDER BY C DESC)
- - 用途:筛选、排序、分组和汇总数据
- 语法:SELECT [列] WHERE [条件] ORDER BY [列] LIMIT [数量]
- 示例:拉取所有订单 > $1,000 的客户,按日期排序
IMPORTRANGE(从其他表格拉取数据):
=IMPORTRANGE(spreadsheet_url, Sheet1!A1:D100)
- - 用途:将多个表格的数据集中到一个主表格
- 设置:首次使用时,需要批准访问权限(提示时点击允许访问)
- 示例:将区域团队的销售数据拉取到一个主仪表盘
ARRAYFORMULA(将公式应用于整列):
=ARRAYFORMULA(IF(A2:A=,,B2:B*C2:C))
- - 用途:自动计算所有行(无需拖动公式)
- 示例:为每个新添加的行自动计算数量×价格
VLOOKUP / XLOOKUP(从另一个表格查找值):
=VLOOKUP(A2, Sheet2!A:B, 2, FALSE)
- - 用途:匹配并拉取相关数据(例如,客户名称 → 拉取其邮箱)
- XLOOKUP(更新版):更灵活,可以向左或向右搜索
FILTER(动态筛选):
=FILTER(A2:D100, D2:D100>1000, C2:C100=Active)
- - 用途:仅显示符合条件的数据(数据变化时自动更新)
- 示例:仅显示收入 > $1,000 的活跃客户
UNIQUE(删除重复项):
=UNIQUE(A2:A100)
- - 用途:从列表中提取唯一值(源数据变化时自动更新)
REGEXEXTRACT(从文本中提取模式):
=REGEXEXTRACT(A2, [0-9]{3}-[0-9]{3}-[0-9]{4})
- - 用途:从杂乱文本中提取电话号码、邮箱、URL或任何模式
- 示例:从邮箱地址中提取域名
IMPORTXML / IMPORTHTML(抓取网页数据):
=IMPORTXML(https://example.com, //h1)
- - 用途:从网站拉取实时数据(价格、标题、表格)
- 示例:自动追踪竞争对手价格
第三步:构建多表格系统
单表格解决方案有限。真正的力量来自将多个表格连接成一个系统。
系统架构模式:
表格1:数据录入(输入表单或手动输入)
↓
表格2:主数据库(清理、验证、丰富)
↓
表格3:仪表盘(图表、摘要、洞察)
↓
表格4:导出/报告(格式化以便分享)
示例:Sheets 中的简单 CRM
表格1:线索录入表单
- - 列:姓名、邮箱、公司、来源、添加日期
- 用途:Google 表单 → 自动填充此表格
- 验证:邮箱格式检查、必填字段
表格2:主线索数据库
- - 使用 IMPORTRANGE 或直接引用从表格1拉取数据
- 添加丰富信息:状态(新/已联系/已合格/已关闭)、最后联系日期、备注
- 公式示例:=IF(ISBLANK(D2), 新, D2)(如果为空则自动设置状态为新)
表格3:仪表盘
- - 总线索数:=COUNTA(MasterDB!A2:A)
- 本周线索数:=COUNTIF(MasterDB!E2:E, >=&TODAY()-7)
- 转化率:=COUNTIF(MasterDB!D2:D, 已关闭)/COUNTA(MasterDB!A2:A)
- 图表:按来源的线索分布(饼图)
表格4:周报
- - 公式:=FILTER(MasterDB!A2:E, MasterDB!E2:E>=TODAY()-7)
- 自动拉取本周线索用于评审会议
关键原则:
- - 一个表格 = 一个用途(不要混合输入、存储和展示)
- 使用公式连接表格(避免手动复制/粘贴)
- 保护重要表格(防止意外编辑)
第四步:学习 Apps Script 基础(Google 的 Sheets JavaScript)
Apps Script 让您可以做公式做不到的事情:发送邮件、调用 API、创建自定义菜单、按计划运行代码。
何时使用 Apps Script:
- - 公式无法完成(发送邮件、调用 API、复杂逻辑)
- 需要按计划运行的自动化(每小时、每天、每周)
- 想要自定义函数或菜单项
如何访问 Apps Script:
- 1. 打开您的 Google Sheet
- 扩展程序 → Apps Script
- 在编辑器中编写代码
示例1:新行添加时发送邮件提醒
javascript
function onEdit(e) {
var sheet = e.source.getActiveSheet();
// 仅在线索录入表格上运行
if (sheet.getName() !== 线索录入表单) return;
// 获取编辑的行和列
var row = e.range.getRow();
var col = e.range.getColumn();
// 如果添加了新行(row > 1 跳过表头)
if (row > 1 && col === 1) {
var name = sheet.getRange(row, 1).getValue();
var email = sheet.getRange(row, 2).getValue();
// 发送邮件通知
MailApp.sendEmail({
to: you@example.com,
subject: 新线索: + name,
body: 姓名: + name + \n邮箱: + email
});
}
}
如何设置:
- 1. 将代码粘贴到 Apps Script 编辑器
- 保存(Ctrl/Cmd + S)
- 设置触发器:触发器(时钟图标)→ 添加触发器 → onEdit → 来自电子表格 → 编辑时 → 保存
- 提示时授权权限
示例2:从 API 获取数据并写入表格
javascript
function fetchAPIData() {
var url = https://api.example.com/data;
var options = {
method: GET,
headers: {