minimax-xlsx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MiniMax 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

任务路由

TaskMethodGuide
READ — analyze existing data
xlsx_reader.py
+ pandas
references/read-analyze.md
CREATE — new xlsx from scratchXML template
references/create.md
+
references/format.md
EDIT — modify existing xlsxXML unpack→edit→pack
references/edit.md
(+
format.md
if styling needed)
FIX — repair broken formulas in existing xlsxXML unpack→fix
<f>
nodes→pack
references/fix.md
VALIDATE — check formulas
formula_check.py
references/validate.md
任务方法指南
读取 — 分析现有数据
xlsx_reader.py
+ pandas
references/read-analyze.md
创建 — 从零开始新建xlsx文件XML模板
references/create.md
+
references/format.md
编辑 — 修改现有xlsx文件XML解包→编辑→打包
references/edit.md
(如需样式处理则加上
format.md
修复 — 修复现有xlsx文件中的损坏公式XML解包→修复
<f>
节点→打包
references/fix.md
验证 — 检查公式
formula_check.py
references/validate.md

READ — Analyze data (read
references/read-analyze.md
first)

读取 — 分析数据(先阅读
references/read-analyze.md

Start with
xlsx_reader.py
for structure discovery, then pandas for custom analysis. Never modify the source file.
Formatting rule: When the user specifies decimal places (e.g. "2 decimal places"), apply that format to ALL numeric values — use
f'{v:.2f}'
on every number. Never output
12875
when
12875.00
is required.
Aggregation rule: Always compute sums/means/counts directly from the DataFrame column — e.g.
df['Revenue'].sum()
. Never re-derive column values before aggregation.
先使用
xlsx_reader.py
进行结构识别,再用pandas进行自定义分析。切勿修改源文件。
格式规则:当用户指定小数位数时(例如“保留2位小数”),需为所有数值应用该格式——对每个数字使用
f'{v:.2f}'
。当要求输出
12875.00
时,绝对不能输出
12875
聚合规则:必须直接从DataFrame列计算求和/平均值/计数——例如
df['Revenue'].sum()
。在聚合之前切勿重新推导列值。

CREATE — XML template (read
references/create.md
+
references/format.md
)

创建 — XML模板(先阅读
references/create.md
+
references/format.md

Copy
templates/minimal_xlsx/
→ edit XML directly → pack with
xlsx_pack.py
. Every derived value MUST be an Excel formula (
<f>SUM(B2:B9)</f>
), never a hardcoded number. Apply font colors per
format.md
.
复制
templates/minimal_xlsx/
→ 直接编辑XML → 使用
xlsx_pack.py
打包。所有派生值必须是Excel公式(
<f>SUM(B2:B9)</f>
),绝对不能是硬编码数字。按照
format.md
设置字体颜色。

EDIT — XML direct-edit (read
references/edit.md
first)

编辑 — 直接编辑XML(先阅读
references/edit.md

CRITICAL — EDIT INTEGRITY RULES:
  1. NEVER create a new
    Workbook()
    for edit tasks. Always load the original file.
  2. The output MUST contain the same sheets as the input (same names, same data).
  3. Only modify the specific cells the task asks for — everything else must be untouched.
  4. After saving output.xlsx, verify it: open with
    xlsx_reader.py
    or
    pandas
    and 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.
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
Workbook()
. Example — fill B3 with a cross-sheet SUM formula:
bash
python3 SKILL_DIR/scripts/xlsx_unpack.py input.xlsx /tmp/xlsx_work/
关键——编辑完整性规则:
  1. 切勿为编辑任务创建新的
    Workbook()
    。始终加载原始文件。
  2. 输出文件必须包含与输入文件完全相同的工作表(相同名称、相同数据)。
  3. 仅修改任务指定的特定单元格——其他所有内容必须保持原样。
  4. 保存output.xlsx后务必验证:使用
    xlsx_reader.py
    pandas
    打开文件,确认原始工作表名称和部分原始数据存在。如果验证失败,说明你生成了错误的文件——交付前必须修复。
切勿对现有文件使用openpyxl往返操作(会损坏VBA、数据透视表、迷你图)。正确做法:解包 → 使用辅助脚本 → 重新打包。
“填充单元格” / “为现有单元格添加公式”属于编辑任务。如果输入文件已存在,且要求你填充、更新或为特定单元格添加公式,必须使用XML编辑路径。切勿创建新的
Workbook()
。示例——在B3单元格中添加跨工作表求和公式:
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.xlsx
The
--border-row
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.
Insert 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
**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
**行查找规则**:当任务要求“在第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
undefined
python3 SKILL_DIR/scripts/xlsx_pack.py /tmp/xlsx_work/ output.xlsx
undefined

FIX — Repair broken formulas (read
references/fix.md
first)

修复 — 修复损坏的公式(先阅读
references/fix.md

This is an EDIT task. Unpack → fix broken
<f>
nodes → pack. Preserve all original sheets and data.
这属于编辑任务。解包→修复损坏的
<f>
节点→打包。保留所有原始工作表和数据。

VALIDATE — Check formulas (read
references/validate.md
first)

验证 — 检查公式(先阅读
references/validate.md

Run
formula_check.py
for static validation. Use
libreoffice_recalc.py
for dynamic recalculation when available.
运行
formula_check.py
进行静态验证。如果可用,使用
libreoffice_recalc.py
进行动态重新计算。

Financial Color Standard

财务颜色标准

Cell RoleFont ColorHex Code
Hard-coded input / assumptionBlue
0000FF
Formula / computed resultBlack
000000
Cross-sheet reference formulaGreen
00B050
单元格角色字体颜色十六进制代码
硬编码输入/假设值蓝色
0000FF
公式/计算结果黑色
000000
跨工作表引用公式绿色
00B050

Key Rules

核心规则

  1. Formula-First: Every calculated cell MUST use an Excel formula, not a hardcoded number
  2. CREATE → XML template: Copy minimal template, edit XML directly, pack with
    xlsx_pack.py
  3. EDIT → XML: Never openpyxl round-trip. Use unpack/edit/pack scripts
  4. Always produce the output file — this is the #1 priority
  5. Validate before delivery:
    formula_check.py
    exit code 0 = safe
  1. 优先使用公式:每个计算单元格必须使用Excel公式,不能是硬编码数字
  2. 创建→XML模板:复制最小模板,直接编辑XML,使用
    xlsx_pack.py
    打包
  3. 编辑→XML:切勿使用openpyxl往返操作。使用解包/编辑/打包脚本
  4. 始终生成输出文件——这是首要任务
  5. 交付前验证
    formula_check.py
    返回码为0表示安全

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 data
bash
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 ...  # 插入带数据的行