xlsx
它能做什么
这项技能教智能体如何处理 Microsoft Excel 文件。它涵盖阅读现有工作表、谨慎编辑且保持文件其余部分完整,以及根据行列表创建新工作簿。
适用场景
- ✓当你希望智能体在 Excel 文件中查找或汇总数据时。
- ✓当你需要更新现有电子表格中的特定单元格,并且不破坏文件时。
- ✓当你希望根据一张行数据表或笔记创建新的 Excel 工作簿的时候。
技能链接
https://github.com/TokenRhythm/opensquilla/blob/main/src/opensquilla/skills/bundled/xlsx/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我有一份销售电子表格,需要修正 F 列的合计,并保留原有格式。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体直接处理文件中的单元格,并把数字、文本、日期和公式视为不同类型的值。它使用 Python 工具读取或写入工作簿,然后返回完成的文件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
xlsx
Work with .xlsx workbooks. The format is OOXML SpreadsheetML — a zip
container of XML parts. Treat each cell as a typed value: a number, a string,
a datetime, or a formula. Mixing the four causes Excel to flag the workbook
or compute incorrect totals.
Decide the path first
| You have | Goal | Path |
|---|---|---|
Existing .xlsx |
Read sheets and cells | A. Inspect |
Existing .xlsx |
Modify specific cells | B. Edit-in-place |
| Nothing or a brief | Build a new workbook | C. Create from scratch |
If the user provides a workbook to update, default to path B and treat the input as the formatting baseline. Choose path C only when the user says "start fresh".
Execution and delivery
Use execute_code with the Python examples below when it is available. Keep
all input and output files in the active workspace, then call
publish_artifact(path="out.xlsx") to deliver the finished workbook.
In a restricted channel, use openpyxl directly; the shell commands below
are optional shortcuts for sessions that expose exec_command. Do not use
Python subprocesses to bypass an unavailable shell tool or request host
execution when the sandbox fails. If execution or a required library is
unavailable, report that limitation and keep the session read-only.
Path A: Inspect
With execute_code:
from openpyxl import load_workbook
wb = load_workbook("book.xlsx", data_only=False)
for ws in wb.worksheets:
print(ws.title, list(ws.values))
wb.close()
python {baseDir}/scripts/inspect_xlsx.py /path/to/book.xlsx
Output:
{
"sheets": [
{
"name": "Q3",
"max_row": 10,
"max_col": 5,
"rows": [
[
{"value": "Metric", "type": "s"},
{"value": "Value", "type": "s"}
],
[
{"value": "Revenue", "type": "s"},
{"value": 2100000, "type": "n"}
]
]
}
]
}
type follows openpyxl conventions: n (number), s (string), d
(datetime), f (formula), b (bool), e (error), inlineStr (inline
string). The helper script reads with data_only=False so formula expressions
are returned literally; pass --data-only to get the cached computed result
instead.
Path B: Edit in place
With execute_code:
from openpyxl import load_workbook
wb = load_workbook("book.xlsx")
wb["Q3"]["B2"] = "=SUM(B3:B10)"
wb.save("edited.xlsx")
wb.close()
python {baseDir}/scripts/edit_xlsx.py book.xlsx ops.json --out edited.xlsx
ops.json:
[
{"op": "set_cell", "sheet": "Q3", "row": 2, "col": 2, "value": "=SUM(B3:B10)"},
{"op": "set_cell", "sheet": "Q3", "row": 5, "col": 1, "value": "Net margin"},
{"op": "rename_sheet", "old": "Sheet1", "new": "Summary"}
]
Rules:
- Rows and columns are 1-based (Excel convention).
- Strings starting with
=are written as formulas (cell.value = "=..."), matching openpyxl behavior. To write a literal=hellouse'=hello(Excel's leading-apostrophe escape) or pass an explicitas_text: true. - Datetimes go in as ISO 8601 strings (
"2026-05-06T09:00:00"); the helper parses them back todatetimeobjects so Excel renders the cell with date format. - Editing a cell does not recalculate dependent formulas. Excel and LibreOffice recalculate on open. If you need cached values immediately, use a calculation engine (out of scope here).
Path C: Create from scratch
python {baseDir}/scripts/create_xlsx.py spec.json --out out.xlsx
Spec:
{
"sheets": [
{
"name": "Sales",
"rows": [
["Region", "Revenue", "Growth"],
["NA", 1200000, "=B2/SUM($B$2:$B$4)"],
["EU", 850000, "=B3/SUM($B$2:$B$4)"]
],
"merged": [{"range": "A1:C1"}],
"freeze": "A2"
}
]
}
For programmatic use:
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.title = "Sales"
ws.append(["Region", "Revenue"])
ws.append(["NA", 1_200_000])
ws["C2"] = "=B2*1.05" # formula
ws.merge_cells("A1:B1")
ws.freeze_panes = "A2"
wb.save("out.xlsx")
See references/openpyxl.md for styles, conditional formatting, charts, and formula references.
Common pitfalls
| Symptom | Cause | Fix |
|---|---|---|
Cell shows =SUM(...) as text, not the result |
Wrote the string with as_text: true or workbook lacks cached values |
Open in Excel and save once; or use a calc engine |
| Date renders as a ser |
常见问题
智能体编辑文件时会保留我原有的格式吗?
会。对于现有工作簿,该技能将你的文件作为格式基准,只改动你指定的单元格。
智能体总是从零开始创建新工作簿吗?
不会。只有在你要求时才会重新开始。否则它会编辑你提供的文件。
如果智能体无法运行 Python 工具怎么办?
该技能要求说明这一限制,并保持会话为只读,而不是绕过缺失的工具。
详情
作者的原始描述
Read, inspect, edit, or create Microsoft Excel `.xlsx` workbooks, including structured data extraction, formula-aware cell edits, and workbook generation from rows.
repo: TokenRhythm/opensquilla
热度
- GitHub 星标
- 7.1k
- 排名
- #13595
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
browser-use
7.1k让你的智能体在 OpenSquilla Desktop 侧边栏浏览器中打开、阅读和操作网页,包括填写表单和进行视觉检查。
deep-research
7.1k教你的智能体进行多轮研究,使用已保存的计划、已追踪的来源,并生成带引用的长篇报告。
docx
7.1k帮你的智能体阅读、编辑或创建 Word .docx 文件,同时保持格式、修订记录和结构完整。
html-coder
7.1k帮你的智能体编写结构清晰的 HTML 页面,包含无障碍表单、媒体和 HTML5 功能,并可作为网页预览打开。