skills/google-sheets-cli/SKILL.md
使用 Python CLI 与 Google Sheets API 交互以读取、更新、批量写入、追加或清空 Google Sheets 在线表格;适用于需要通过 OAuth 授权操作 Google Workspace 表格的场景。
npx skillsauth add dcjanus/prompts google-sheets-cliInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
通过本 skill 调用 Google Sheets API。适合读取和编辑 Google Sheets 在线文档中的单元格值。
先进入 skill 目录,再直接执行脚本:
cd skills/google-sheets-cli
./scripts/gsheets_cli.py --json values get --spreadsheet-id <spreadsheet-id> --range "Sheet1!A1:D20"
uv run python 或 python 调用脚本;脚本自身带 uv shebang。--json,并且全局参数必须放在子命令前。./scripts/gsheets_cli.py <command> --help。OAuth 通常只需要配置一次;日常任务不要把认证细节加载进上下文。
./scripts/gsheets_cli.py --json auth doctor。常用命令族:
auth login|doctor|logout|pathsspreadsheet getvalues get|update|batch-update|append|clear示例:
./scripts/gsheets_cli.py --json spreadsheet get --spreadsheet-id <spreadsheet-id>
./scripts/gsheets_cli.py --json values get --spreadsheet-id <spreadsheet-id> --range "Sheet1!A1:D20"
./scripts/gsheets_cli.py --json values update --spreadsheet-id <spreadsheet-id> --range "Sheet1!B2" --values-json '[["DONE"]]'
./scripts/gsheets_cli.py --json values append --spreadsheet-id <spreadsheet-id> --range "Sheet1!A:D" --values-json '[["a","b","c","d"]]'
批量写入:
./scripts/gsheets_cli.py --json values batch-update \
--spreadsheet-id <spreadsheet-id> \
--updates-json '[{"range":"Sheet1!B2","values":[["DONE"]]},{"range":"Sheet1!C2","values":[["ok"]]}]'
复杂 JSON 可以使用 @path 从文件读取:
./scripts/gsheets_cli.py --json values batch-update \
--spreadsheet-id <spreadsheet-id> \
--updates-json @/tmp/sheets-updates.json
需要确认在线表格的列结构、table 范围、filter、banded row 样式、dropdown 选项、列宽、日期格式等信息时,优先走只读流程:
./scripts/gsheets_cli.py --json spreadsheet get --spreadsheet-id <spreadsheet-id>
metadata 通常足够看到 sheet id、sheet title、basicFilter、bandedRanges、tables[].range、tables[].columnProperties,包括 table dropdown 列的选项。
values get 限定 A1 range:./scripts/gsheets_cli.py --json values get \
--spreadsheet-id <spreadsheet-id> \
--range "Sheet1!A1:H40"
spreadsheet get --include-grid-data;它会拉取全量 grid data,可能很慢。需要读取单元格 effectiveFormat、列宽、行高、日期格式等精细格式时,复用本 CLI 的 OAuth token,通过 Sheets API 原生 spreadsheets.get 指定 ranges 和 fields 做窄范围只读查询:uv run --with google-api-python-client --with google-auth-httplib2 --with google-auth-oauthlib python - <<'PY'
from pathlib import Path
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
spreadsheet_id = "<spreadsheet-id>"
creds = Credentials.from_authorized_user_file(
str(Path.home() / ".config/google-sheets-cli/token.json"),
["https://www.googleapis.com/auth/spreadsheets"],
)
service = build("sheets", "v4", credentials=creds)
resp = service.spreadsheets().get(
spreadsheetId=spreadsheet_id,
ranges=["'Sheet1'!A1:H5"],
includeGridData=True,
fields="sheets(properties(sheetId,title),data(columnMetadata,rowData(values(formattedValue,effectiveFormat,dataValidation))))",
).execute()
print(resp)
PY
values get 备份目标范围到 /tmp/...json,并把所有写操作限定到目标 sheet/range;不要误动其它 tab。values update 只改值,不会自动扩展 Google Sheets table 的范围、列名、filter、banded range 或 dropdown metadata。新增列后,如果要保持 table 结构,需要用 Sheets API spreadsheets.batchUpdate 调 updateTable、updateBanding、setBasicFilter、updateDimensionProperties 等请求,并使用目标 sheet 的 sheetId 限定范围。TableColumnDataValidationRule 只能表达 dropdown 的 ONE_OF_LIST 选项,不能表达 Google Sheets UI 里的 dropdown chip 背景色、选项颜色、display style 或 multi-select 等 UI metadata。用 updateTable 重写 columnProperties 时,原 UI 选项颜色可能丢失。copyPaste + PASTE_DATA_VALIDATION 不可靠,条件格式也不等价:设置背景色会把整个单元格染色,只设置文字色也只是灰色 chip 内的文字变色,都会偏离原生 chip 视觉。遇到这类需求时,应明确告知这是 Google Sheets API 缺口,保留现状、回退写入,或让用户在 UI/模板中手工维护。setDataValidation;Google Sheets 会报错类似 无法对指定类型的列中的单元格进行此操作。应通过 updateTable.columnProperties[].dataValidationRule 维护 table dropdown 选项。CLI 使用 Google Sheets scope:https://www.googleapis.com/auth/spreadsheets。
该 scope 可读取和修改用户有权限访问的 Google Sheets。若公司 Workspace 阻止该 OAuth client 访问,需由 Workspace 管理员允许对应 OAuth Client ID。
data-ai
用干净的独立 subagent 反复做代码审查、由主 agent 判断审查意见价值、修复有效问题并提交推送,直到连续三轮没有有价值审查意见。适用于用户要求 review/fix loop、clean review cycle、创建新 subagent 审查当前修改、反复 review 到没有问题、或“连续三次没有有价值建议”这类任务。
development
为当前 Codex thread 设置名称;仅当用户手动调用或明确要求命名、重命名、整理当前 Codex 会话标题时使用,永远不要自动调用。
testing
编写或更新 GitHub/GitLab Issue、PR、MR 的标题与正文;适用于创建、修改、重写 reviewer-facing 描述、Risks、Breaking Change、避免低价值验证噪声与本地路径泄露等场景。PR/MR 正文默认禁止 Validation;只有 CI/diff 看不到的高信噪比行为证据才允许写。
testing
用于向 GitHub 上游提交 PR 前,在用户 fork 内创建草稿 PR/内部 PR 做低干扰收敛,并保留必要的上游 issue/PR/discussion 背景链接;当用户提到草稿 PR、内部 PR、fork draft、先内部 review/CI、或 red/green 证据时使用。