Google Sheets API Skill (Advanced)
Purpose
Provide a production-ready Google Sheets CLI for OpenClaw. This skill supports data reads/writes, batch operations, formatting, and sheet management with service account authentication.
Best fit
- - You need a repeatable CLI for automation tasks.
- You want JSON-in/JSON-out for pipelines.
- You need more than basic read/write (formatting, sheet ops, batch updates).
Not a fit
- - You must use end-user OAuth consent flows (this skill is service-account focused).
- You only need lightweight, one-off edits.
One-time setup
- 1. Create or select a Google Cloud project.
- Enable the Google Sheets API.
- Create a service account and download its JSON key.
- Share target spreadsheets with the service account email.
Install
CODEBLOCK0
Run
CODEBLOCK1
You can also use npm:
CODEBLOCK2
Credentials
Supported sources (first match wins):
- -
GOOGLE_SHEETS_CREDENTIALS_JSON (inline JSON string) - INLINECODE1 (file path)
- INLINECODE2 (file path)
- INLINECODE3 (file path)
- INLINECODE4 ,
./credentials.json, INLINECODE6 - INLINECODE7
Input conventions
- - JSON values can be inline or loaded from file using
@path. - Write/append expect a 2D array of values.
Example data.json:
CODEBLOCK3
Command map (high level)
Data:
- -
read, write, append, clear, batchGet, INLINECODE15
Formatting:
- -
format, getFormat, borders, merge, unmerge, INLINECODE21
Layout:
- -
resize, autoResize, INLINECODE24
Sheets:
- -
create, info, addSheet, deleteSheet, INLINECODE29
Advanced:
- -
batch (raw spreadsheets.batchUpdate requests)
Operational guidance
- - Prefer read-only scope for read workflows when possible.
- Add retry with exponential backoff for
429 and transient 5xx errors. - Keep request payloads small to avoid limit issues.
Expected output
- - JSON to stdout; non-zero exit code on errors.
Security notes
- - Never log or commit service account keys.
- Share spreadsheets only with the service account email required by this skill.
Google Sheets API 技能(高级版)
目的
为OpenClaw提供生产就绪的Google Sheets命令行工具。该技能支持数据读写、批量操作、格式设置和电子表格管理,采用服务账户认证方式。
适用场景
- - 需要可重复使用的命令行工具执行自动化任务
- 希望实现JSON输入/JSON输出的管道操作
- 需要超越基础读写功能(格式设置、工作表操作、批量更新)
不适用场景
- - 必须使用终端用户OAuth授权流程(本技能专注于服务账户)
- 仅需轻量级的一次性编辑操作
一次性设置
- 1. 创建或选择Google Cloud项目
- 启用Google Sheets API
- 创建服务账户并下载JSON密钥文件
- 使用服务账户邮箱共享目标电子表格
安装
bash
cd google-sheet-api
npm install
运行
bash
node scripts/sheets-cli.js help
node scripts/sheets-cli.js read
Sheet1!A1:C10
node scripts/sheets-cli.js append Sheet1!A:B @data.json
也可使用npm:
bash
npm run sheets -- read Sheet1!A1:C10
凭据配置
支持的来源(按优先级匹配):
- - GOOGLESHEETSCREDENTIALSJSON(内联JSON字符串)
- GOOGLESERVICEACCOUNTKEY(文件路径)
- GOOGLESHEETSKEYFILE(文件路径)
- GOOGLEAPPLICATION_CREDENTIALS(文件路径)
- ./service-account.json、./credentials.json、./google-service-account.json
- ~/.config/google-sheets/credentials.json
输入规范
- - JSON值可直接内联或通过@path从文件加载
- 写入/追加操作需使用二维数组格式
示例 data.json:
json
[[姓名,分数],[Alice,95]]
命令映射(高级概览)
数据操作:
- - read、write、append、clear、batchGet、batchWrite
格式设置:
- - format、getFormat、borders、merge、unmerge、copyFormat
布局调整:
- - resize、autoResize、freeze
工作表管理:
- - create、info、addSheet、deleteSheet、renameSheet
高级功能:
- - batch(原始spreadsheets.batchUpdate请求)
操作指南
- - 读取工作流中尽量使用只读权限范围
- 对429和临时性5xx错误采用指数退避重试策略
- 保持请求负载小巧以避免限制问题
预期输出
- - JSON格式输出至标准输出;错误时返回非零退出码
安全注意事项
- - 切勿记录或提交服务账户密钥
- 仅与本技能所需的服务账户邮箱共享电子表格