minimax-xlsx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMiniMax XLSX Skill
MiniMax XLSX Skill
Handle the request directly. Do NOT spawn sub-agents. Always write the output file the user requests.
直接处理请求,不要生成子Agent。始终生成用户要求的输出文件。
Task Routing
任务路由
| Task | Method | Guide |
|---|---|---|
| READ — analyze existing data | | |
| CREATE — new xlsx from scratch | XML template | |
| EDIT — modify existing xlsx | XML unpack→edit→pack | |
| FIX — repair broken formulas in existing xlsx | XML unpack→fix | |
| VALIDATE — check formulas | | |
| 任务 | 方法 | 指南 |
|---|---|---|
| 读取 — 分析现有数据 | | |
| 创建 — 从零开始新建xlsx文件 | XML模板 | |
| 编辑 — 修改现有xlsx文件 | XML解包→编辑→打包 | |
| 修复 — 修复现有xlsx文件中的损坏公式 | XML解包→修复 | |
| 验证 — 检查公式 | | |
READ — Analyze data (read references/read-analyze.md
first)
references/read-analyze.md读取 — 分析数据(先阅读references/read-analyze.md
)
references/read-analyze.mdStart with for structure discovery, then pandas for custom analysis. Never modify the source file.
xlsx_reader.pyFormatting rule: When the user specifies decimal places (e.g. "2 decimal places"), apply that format to ALL numeric values — use on every number. Never output when is required.
f'{v:.2f}'1287512875.00Aggregation rule: Always compute sums/means/counts directly from the DataFrame column — e.g. . Never re-derive column values before aggregation.
df['Revenue'].sum()先使用进行结构识别,再用pandas进行自定义分析。切勿修改源文件。
xlsx_reader.py格式规则:当用户指定小数位数时(例如“保留2位小数”),需为所有数值应用该格式——对每个数字使用。当要求输出时,绝对不能输出。
f'{v:.2f}'12875.0012875聚合规则:必须直接从DataFrame列计算求和/平均值/计数——例如。在聚合之前切勿重新推导列值。
df['Revenue'].sum()CREATE — XML template (read references/create.md
+ references/format.md
)
references/create.mdreferences/format.md创建 — XML模板(先阅读references/create.md
+ references/format.md
)
references/create.mdreferences/format.mdCopy → edit XML directly → pack with . Every derived value MUST be an Excel formula (), never a hardcoded number. Apply font colors per .
templates/minimal_xlsx/xlsx_pack.py<f>SUM(B2:B9)</f>format.md复制 → 直接编辑XML → 使用打包。所有派生值必须是Excel公式(),绝对不能是硬编码数字。按照设置字体颜色。
templates/minimal_xlsx/xlsx_pack.py<f>SUM(B2:B9)</f>format.mdEDIT — XML direct-edit (read references/edit.md
first)
references/edit.md编辑 — 直接编辑XML(先阅读references/edit.md
)
references/edit.mdCRITICAL — EDIT INTEGRITY RULES:
- NEVER create a new for edit tasks. Always load the original file.
Workbook() - The output MUST contain the same sheets as the input (same names, same data).
- Only modify the specific cells the task asks for — everything else must be untouched.
- After saving output.xlsx, verify it: open with or
xlsx_reader.pyand confirm the original sheet names and a sample of original data are present. If verification fails, you wrote the wrong file — fix it before delivering.pandas
Never use openpyxl round-trip on existing files (corrupts VBA, pivots, sparklines). Instead: unpack → use helper scripts → repack.
"Fill cells" / "Add formulas to existing cells" = EDIT task. If the input file already exists and you are told to fill, update, or add formulas to specific cells, you MUST use the XML edit path. Never create a new . Example — fill B3 with a cross-sheet SUM formula:
Workbook()bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/关键——编辑完整性规则:
- 切勿为编辑任务创建新的。始终加载原始文件。
Workbook() - 输出文件必须包含与输入文件完全相同的工作表(相同名称、相同数据)。
- 仅修改任务指定的特定单元格——其他所有内容必须保持原样。
- 保存output.xlsx后务必验证:使用或
xlsx_reader.py打开文件,确认原始工作表名称和部分原始数据存在。如果验证失败,说明你生成了错误的文件——交付前必须修复。pandas
切勿对现有文件使用openpyxl往返操作(会损坏VBA、数据透视表、迷你图)。正确做法:解包 → 使用辅助脚本 → 重新打包。
“填充单元格” / “为现有单元格添加公式”属于编辑任务。如果输入文件已存在,且要求你填充、更新或为特定单元格添加公式,必须使用XML编辑路径。切勿创建新的。示例——在B3单元格中添加跨工作表求和公式:
Workbook()bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/Find the target sheet's XML via xl/workbook.xml → xl/_rels/workbook.xml.rels
通过xl/workbook.xml → xl/_rels/workbook.xml.rels找到目标工作表的XML
Then use the Edit tool to add <f> inside the target <c> element:
然后使用编辑工具在目标<c>元素内添加<f>:
<c r="B3"><f>SUM('Sales Data'!D2:D13)</f><v></v></c>
<c r="B3"><f>SUM('Sales Data'!D2:D13)</f><v></v></c>
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
**Add a column** (formulas, numfmt, styles auto-copied from adjacent column):
```bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/
python3 SKILL_DIR/scripts/xlsx_add_column.py /tmp/xlsx_work/ --col G \
--sheet "Sheet1" --header "% of Total" \
--formula '=F{row}/$F$10' --formula-rows 2:9 \
--total-row 10 --total-formula '=SUM(G2:G9)' --numfmt '0.0%' \
--border-row 10 --border-style medium
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsxThe flag applies a top border to ALL cells in that row (not just the new column). Use it when the task requires accounting-style borders on total rows.
--border-rowInsert a row (shifts existing rows, updates SUM formulas, fixes circular refs):
bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
**添加列**(公式、数字格式、样式自动从相邻列复制):
```bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/
python3 SKILL_DIR/scripts/xlsx_add_column.py /tmp/xlsx_work/ --col G \
--sheet "Sheet1" --header "占比" \
--formula '=F{row}/$F$10' --formula-rows 2:9 \
--total-row 10 --total-formula '=SUM(G2:G9)' --numfmt '0.0%' \
--border-row 10 --border-style medium
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx--border-row插入行(移动现有行、更新求和公式、修复循环引用):
bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/IMPORTANT: Find the correct --at row by searching for the label text
重要提示:通过在工作表XML中搜索标签文本找到正确的--at行号
in the worksheet XML, NOT by using the row number from the prompt.
提示中可能说“第5行(办公租金)”,但办公租金实际可能在第4行。务必先通过文本标签定位行。
The prompt may say "row 5 (Office Rent)" but Office Rent might actually
—
be at row 4. Always locate the row by its text label first.
—
python3 SKILL_DIR/scripts/xlsx_insert_row.py /tmp/xlsx_work/ --at 5
--sheet "Budget FY2025" --text A=Utilities
--values B=3000 C=3000 D=3500 E=3500
--formula 'F=SUM(B{row}:E{row})' --copy-style-from 4 python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
--sheet "Budget FY2025" --text A=Utilities
--values B=3000 C=3000 D=3500 E=3500
--formula 'F=SUM(B{row}:E{row})' --copy-style-from 4 python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
**Row lookup rule**: When the task says "after row N (Label)", always find the row by searching for "Label" in the worksheet XML (`grep -n "Label" /tmp/xlsx_work/xl/worksheets/sheet*.xml` or check sharedStrings.xml). Use the actual row number + 1 for `--at`. Do NOT call `xlsx_shift_rows.py` separately — `xlsx_insert_row.py` calls it internally.
**Apply row-wide borders** (e.g. accounting line on a TOTAL row):
After running helper scripts, apply borders to ALL cells in the target row, not just newly added cells. In `xl/styles.xml`, append a new `<border>` with the desired style, then append a new `<xf>` in `<cellXfs>` that clones each cell's existing `<xf>` but sets the new `borderId`. Apply the new style index to every `<c>` in the row via the `s` attribute:
```xml
<!-- In xl/styles.xml, append to <borders>: -->
<border>
<left/><right/><top style="medium"/><bottom/><diagonal/>
</border>
<!-- Then append to <cellXfs> an xf clone with the new borderId for each existing style -->Key rule: When a task says "add a border to row N", iterate over ALL cells A through the last column, not just newly added cells.
Manual XML edit (for anything the helper scripts don't cover):
bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/python3 SKILL_DIR/scripts/xlsx_insert_row.py /tmp/xlsx_work/ --at 5
--sheet "Budget FY2025" --text A=水电费
--values B=3000 C=3000 D=3500 E=3500
--formula 'F=SUM(B{row}:E{row})' --copy-style-from 4 python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
--sheet "Budget FY2025" --text A=水电费
--values B=3000 C=3000 D=3500 E=3500
--formula 'F=SUM(B{row}:E{row})' --copy-style-from 4 python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
**行查找规则**:当任务要求“在第N行(标签)之后插入行”时,务必在工作表XML中搜索“标签”文本(使用`grep -n "Label" /tmp/xlsx_work/xl/worksheets/sheet*.xml`或查看sharedStrings.xml)。使用实际行号+1作为`--at`参数的值。切勿单独调用`xlsx_shift_rows.py`——`xlsx_insert_row.py`会在内部调用它。
**为整行添加边框**(例如在总计行添加会计风格线条):
运行辅助脚本后,为目标行的所有单元格添加边框,而不仅仅是新增单元格。在`xl/styles.xml`中,添加一个新的`<border>`元素设置所需样式,然后在`<cellXfs>`中添加一个新的`<xf>`元素,克隆每个单元格现有的`<xf>`但设置新的`borderId`。通过`s`属性将新样式索引应用到该行的每个`<c>`元素:
```xml
<!-- 在xl/styles.xml的<borders>中添加: -->
<border>
<left/><right/><top style="medium"/><bottom/><diagonal/>
</border>
<!-- 然后在<cellXfs>中为每个现有样式添加带有新borderId的xf克隆 -->关键规则:当任务要求“为第N行添加边框”时,要遍历从A列到最后一列的所有单元格,而不仅仅是新增的单元格。
手动编辑XML(处理辅助脚本未覆盖的情况):
bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/... edit XML with the Edit tool ...
... 使用编辑工具编辑XML ...
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
undefinedpython3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
undefinedFIX — Repair broken formulas (read references/fix.md
first)
references/fix.md修复 — 修复损坏的公式(先阅读references/fix.md
)
references/fix.mdThis is an EDIT task. Unpack → fix broken nodes → pack. Preserve all original sheets and data.
<f>这属于编辑任务。解包→修复损坏的节点→打包。保留所有原始工作表和数据。
<f>VALIDATE — Check formulas (read references/validate.md
first)
references/validate.md验证 — 检查公式(先阅读references/validate.md
)
references/validate.mdRun for static validation. Use for dynamic recalculation when available.
formula_check.pylibreoffice_recalc.py运行进行静态验证。如果可用,使用进行动态重新计算。
formula_check.pylibreoffice_recalc.pyFinancial Color Standard
财务颜色标准
| Cell Role | Font Color | Hex Code |
|---|---|---|
| Hard-coded input / assumption | Blue | |
| Formula / computed result | Black | |
| Cross-sheet reference formula | Green | |
| 单元格角色 | 字体颜色 | 十六进制代码 |
|---|---|---|
| 硬编码输入/假设值 | 蓝色 | |
| 公式/计算结果 | 黑色 | |
| 跨工作表引用公式 | 绿色 | |
Key Rules
核心规则
- Formula-First: Every calculated cell MUST use an Excel formula, not a hardcoded number
- CREATE → XML template: Copy minimal template, edit XML directly, pack with
xlsx_pack.py - EDIT → XML: Never openpyxl round-trip. Use unpack/edit/pack scripts
- Always produce the output file — this is the #1 priority
- Validate before delivery: exit code 0 = safe
formula_check.py
- 优先使用公式:每个计算单元格必须使用Excel公式,不能是硬编码数字
- 创建→XML模板:复制最小模板,直接编辑XML,使用打包
xlsx_pack.py - 编辑→XML:切勿使用openpyxl往返操作。使用解包/编辑/打包脚本
- 始终生成输出文件——这是首要任务
- 交付前验证:返回码为0表示安全
formula_check.py
Utility Scripts
实用脚本
bash
python3 SKILL_DIR/scripts/xlsx_reader.py input.xlsx # structure discovery
python3 SKILL_DIR/scripts/formula_check.py file.xlsx --json # formula validation
python3 SKILL_DIR/scripts/formula_check.py file.xlsx --report # standardized report
python3 SKILL_DIR/scripts/xlsx_unpack.py in.xlsx /tmp/work/ # unpack for XML editing
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/work/ out.xlsx # repack after editing
python3 SKILL_DIR/scripts/xlsx_shift_rows.py /tmp/work/ insert 5 1 # shift rows for insertion
python3 SKILL_DIR/scripts/xlsx_add_column.py /tmp/work/ --col G ... # add column with formulas
python3 SKILL_DIR/scripts/xlsx_insert_row.py /tmp/work/ --at 6 ... # insert row with databash
python3 SKILL_DIR/scripts/xlsx_reader.py input.xlsx # 结构识别
python3 SKILL_DIR/scripts/formula_check.py file.xlsx --json # 公式验证
python3 SKILL_DIR/scripts/formula_check.py file.xlsx --report # 标准化报告
python3 SKILL_DIR/scripts/xlsx_unpack.py in.xlsx /tmp/work/ # 解包以进行XML编辑
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/work/ out.xlsx # 编辑后重新打包
python3 SKILL_DIR/scripts/xlsx_shift_rows.py /tmp/work/ insert 5 1 # 为插入行移动现有行
python3 SKILL_DIR/scripts/xlsx_add_column.py /tmp/work/ --col G ... # 添加带公式的列
python3 SKILL_DIR/scripts/xlsx_insert_row.py /tmp/work/ --at 6 ... # 插入带数据的行