Google Docs 与 Sheets AI 辅助
Google Docs 写报告、Sheets 做分析——Claude 能在这两个场景都显著提速,关键是掌握正确的工作流。
Docs + Sheets 工作流
graph TD
DOCS[Google Docs] --> D1[内容起草]
DOCS --> D2[文档审查]
DOCS --> D3[格式标准化]
SHEETS[Google Sheets] --> S1[数据分析]
SHEETS --> S2[公式生成]
SHEETS --> S3[报告自动化]
D1 --> CLAUDE[Claude 辅助]
D2 --> CLAUDE
S1 --> CLAUDE
S2 --> CLAUDE
CLAUDE --> C1[内容生成]
CLAUDE --> C2[错误检查]
CLAUDE --> C3[公式/脚本]
CLAUDE --> C4[可视化建议]
style CLAUDE fill:#c8e6c9,stroke:#388e3c,stroke-width:2px
Docs 与 Sheets 自动化工具
"""
Google Docs 与 Sheets AI 辅助工作流
(使用 Google Apps Script 语法演示,实际在 Apps Script 编辑器中运行)
"""
from dataclasses import dataclass, field
@dataclass
class DocTemplate:
"""Google Docs 文档模板"""
name: str
doc_type: str
sections: list[str]
claude_prompts: dict[str, str] # section -> prompt
estimated_time_min: int
@dataclass
class SheetsFormula:
"""Sheets 公式助手"""
task: str
formula: str
explanation: str
example: str
apps_script: str = ""
class GoogleDocsWorkflow:
"""Google Docs AI 辅助工作流"""
TEMPLATES = [
DocTemplate(
name="产品需求文档 (PRD)",
doc_type="PRD",
sections=[
"背景与问题定义",
"目标用户与使用场景",
"功能需求",
"非功能需求",
"成功指标",
"排期与里程碑",
],
claude_prompts={
"背景与问题定义": """基于以下背景信息,写一个清晰的问题定义段落(150-200字):
产品名称: $product_name
当前痛点: $pain_points
目标: $goal
要求:
- 从用户视角描述问题
- 量化痛点(如果有数据)
- 避免直接给出解决方案""",
"成功指标": """为以下功能定义 SMART 成功指标:
功能: $feature_name
业务目标: $business_goal
生成 3-5 个指标,格式:
| 指标名称 | 基线值 | 目标值 | 时间框架 | 测量方式 |""",
},
estimated_time_min=45,
),
DocTemplate(
name="周报/月报模板",
doc_type="Report",
sections=["本期完成", "进行中", "下期计划", "风险与阻碍", "数据摘要"],
claude_prompts={
"本期完成": """将以下工作内容整理为专业的周报格式:
原始记录: $raw_tasks
要求:
- 按项目/模块分组
- 每条用动词开头
- 加上量化结果(如有)
- 最多 8 条,超出的合并""",
"数据摘要": """将以下原始数据整理为图表描述段落:
数据: $data
输出格式:
关键指标表格 + 2句趋势分析 + 1句关注点""",
},
estimated_time_min=15,
),
]
@classmethod
def get_apps_script_addon(cls) -> str:
"""Google Apps Script:在 Docs 中调用 Claude"""
return '''
// Google Apps Script - 在 Docs 中使用 Claude
// 在 Tools > Script Editor 中添加此代码
function onOpen() {
DocumentApp.getUi()
.createMenu("Claude AI")
.addItem("改写选中文本", "rewriteSelection")
.addItem("摘要全文", "summarizeDoc")
.addItem("检查语法", "grammarCheck")
.addItem("生成标题", "generateTitle")
.addToUi();
}
function callClaude(prompt) {
const apiKey = PropertiesService.getScriptProperties()
.getProperty("ANTHROPIC_API_KEY");
const payload = {
model: "claude-sonnet-4-5-20251001",
max_tokens: 1024,
messages: [{ role: "user", content: prompt }]
};
const options = {
method: "post",
contentType: "application/json",
headers: {
"x-api-key": apiKey,
"anthropic-version": "2023-06-01"
},
payload: JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(
"https://api.anthropic.com/v1/messages", options
);
const result = JSON.parse(response.getContentText());
return result.content[0].text;
}
function rewriteSelection() {
const doc = DocumentApp.getActiveDocument();
const selection = doc.getSelection();
if (!selection) {
DocumentApp.getUi().alert("请先选中要改写的文字");
return;
}
const elements = selection.getSelectedElements();
const text = elements.map(e => e.getElement().asText().getText()).join(" ");
const result = callClaude(
`改写以下文本,使其更简洁专业(保持原意):\\n\\n${text}`
);
// 替换选中内容
elements[0].getElement().asText().setText(result);
}
function summarizeDoc() {
const body = DocumentApp.getActiveDocument().getBody().getText();
const summary = callClaude(
`摘要以下文档的关键要点(100字以内):\\n\\n${body.substring(0, 5000)}`
);
const ui = DocumentApp.getUi();
ui.alert("文档摘要", summary, ui.ButtonSet.OK);
}
'''
class GoogleSheetsFormulas:
"""Google Sheets 常用公式 + Apps Script 自动化"""
FORMULA_EXAMPLES = [
SheetsFormula(
task="按月份汇总销售数据",
formula='=SUMIFS(C:C, MONTH(A:A), MONTH(TODAY()), YEAR(A:A), YEAR(TODAY()))',
explanation="对当月的销售额(C列)求和,A列为日期",
example="本月销售总额:¥128,450",
apps_script="""
function monthlySummary() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = sheet.getDataRange().getValues();
const now = new Date();
let total = 0;
data.forEach(row => {
const date = new Date(row[0]);
if (date.getMonth() === now.getMonth() &&
date.getFullYear() === now.getFullYear()) {
total += parseFloat(row[2]) || 0;
}
});
Logger.log(`本月销售额: ${total}`);
return total;
}""",
),
SheetsFormula(
task="找出重复值",
formula='=COUNTIF($A$2:$A$1000, A2) > 1',
explanation="返回 TRUE 表示该值有重复,配合条件格式高亮显示",
example="把公式放 B 列,再用条件格式把 B 列为 TRUE 的行高亮",
),
SheetsFormula(
task="动态下拉菜单(依赖型)",
formula='=INDIRECT("Sheet2!"&MATCH(A2,{"类目A","类目B"},0)*100&":"&MATCH(A2,{"类目A","类目B"},0)*100+50)',
explanation="选择 A2 的类目后,B2 的下拉选项自动更新",
example="先选产品类目,再在子类目列选具体产品",
),
]
@classmethod
def generate_formula_from_description(cls, description: str) -> str:
"""演示:根据描述生成 Sheets 公式的提示词"""
return f"""你是 Google Sheets 专家。根据以下需求生成公式:
需求: {description}
请提供:
1. 公式(可直接复制使用)
2. 说明(每个参数的含义)
3. 注意事项(可能的错误和处理方式)
4. 如果复杂逻辑适合用 Apps Script,也提供脚本版本"""
# 演示
print("=== Google Docs 模板库 ===\n")
for template in GoogleDocsWorkflow.TEMPLATES:
print(f"【{template.name}】预计 {template.estimated_time_min} 分钟")
for section in template.sections:
has_prompt = "🤖" if section in template.claude_prompts else " "
print(f" {has_prompt} {section}")
print()
print("\n=== Sheets 公式助手 ===\n")
for formula in GoogleSheetsFormulas.FORMULA_EXAMPLES:
print(f"任务: {formula.task}")
print(f"公式: {formula.formula}")
print(f"说明: {formula.explanation}")
if formula.apps_script:
print(f" → 也提供 Apps Script 自动化版本")
print()
print("\n=== Apps Script Docs 插件代码(前300字)===")
print(GoogleDocsWorkflow.get_apps_script_addon()[:300] + "...")
Sheets 公式 vs Apps Script 决策
| 场景 | 推荐方案 | 原因 |
|---|---|---|
| 简单计算/汇总 | Sheets 公式 | 实时更新,无需维护 |
| 复杂跨表逻辑 | Apps Script | 公式嵌套过深难维护 |
| 定时自动运行 | Apps Script Trigger | 公式无法定时触发 |
| 与外部 API 交互 | Apps Script | 公式无法发 HTTP 请求 |
| 批量数据处理 | Apps Script | 公式对大数据集性能差 |
行动清单
- [ ] 在 Google Apps Script 编辑器中安装 Claude 辅助插件(见上方代码),实现文档内 AI 快捷键
- [ ] 建立 Docs 模板库:PRD/周报/会议纪要各准备一个 Claude 提示词增强版本
- [ ] 对复杂 Sheets 需求,用"你是 Sheets 专家,根据以下需求生成公式"模式提问——比搜索快 3 倍
- [ ] 探索 Apps Script + Claude API:让 Sheets 每天自动从 Gmail 提取数据并生成报告
- [ ] 为 Apps Script 配置
ANTHROPIC_API_KEY:在 Script Properties 中设置(不要硬编码) - [ ] 建立 Docs 写作 SOP:先让 Claude 生成大纲 → 人工确认结构 → Claude 扩写各节 → 人工润色
下一节:03-Drive文档分析与智能搜索 — 让 Claude 理解你的整个 Google Drive 知识库。