SpreadsheetBench: 真实复杂电子表格操作基准与 Agent 优化全景

基于 400 道真实 Excel/CSV 复杂表格操纵、公式编写与单元格多阶交互执行流
Benchmark: SpreadsheetBench (Verified 400 Subset)Source: KAKA22/SpreadsheetBench / Verified 400 TarballTask Category: Sheet / Cell Level Excel ManipulationDataset Size: 400 Verified Realistic Tasks with XLSXTarget Framework: SkillOpt Spreadsheet Agent OptimizerVisual Spec: ELLIPSE-FLOW-V1 (Academic TikZ & 1:1 Aligned Trace)
FIGURE 1 SpreadsheetBench 执行沙箱与 SkillOpt 优化系统架构拓扑

展现智能体在面对真实业务表格时的端到端拓扑。输入包括多工作表(Sheets)、公式逻辑与自然语言业务指令。系统通过生成 Python/openpyxl 脚本在隔离沙箱中执行,与真实 Excel 预期单元格区域(Answer Position)比对,基于执行报错与数值差异进行策略退火更新。

SPREADSHEET EXECUTION PIPELINE
[Layer 1: Excel Workbooks & Instruction Loading]
Tarball Unpack:
spreadsheetbench_verified_400/
• 真实 .xlsx 业务工作薄
Instruction Types:
Cell-Level, Sheet-Level, Cross-Table Lookup
Ground Truth Area:
标准答案工作表 + 单元格边界(如 A3:D32)
▼ (Sandbox Code Execution & Cell Diff Feedback)
[Layer 2: Sandboxed Python Rollout & Cell Value Diff Loop]
1. Code Rollout
Agent 生成 openpyxl 代码
在隔离沙箱中加载并修改表格
2. Matrix Diff Tracing
逐单元格对比数值与公式
捕获行列偏移与类型错位
3. Formula Proposer
反思索引错位(0-index vs 1-index)
优化跨表 VLOOKUP 策略
4. Gate Matrix Accuracy
严格单元格精确率验证
必须 100% 匹配目标区域
▼ (Production-Ready Table Skill)
[Layer 3: Evaluation Metrics & Automated Artifacts]
Cell Accuracy (CA):
匹配单元格数量 / 目标总格数
Sheet Success Rate (SR):
整张表完全吻合的严格通过率
Saved Skill:
outputs/spreadsheet_run/best_skill.md
FIGURE 2 微观表格操纵与真实任务样本 1:1 对齐推演

对齐展示 SpreadsheetBench 官方 Verified 第一条真实样本(id: 13-1,关于跨多工作表数据去重合并的任务)。

Stage 0 Spreadsheet Workbook Ingestion (工作簿载入与操作目标解析)
Spreadsheet Dataloader
skillopt/envs/spreadsheet/env.py:38

加载 spreadsheet/13-1 原始文件,解析元数据:要求将 'RANGES' 表格数据合并至 'LISTS' 表,并写入目标区域。

Target Range: LISTS!A3:D32
➔ parse
REAL SPREADSHEET TASK [13-1] Sheet-Level Manipulation
[Instruction]: "How can I combine data from a 'RANGES' sheet to a 'LISTS' sheet, by matching duplicates based on the 'DATE' and 'REF' columns in columns B and C, and add a 'TOTAL' row to sum up the amounts? Additionally, since new ranges with headers will be added to the 'RANGES' sheet, how do I ensure to delete the old ranges in the 'LISTS' sheet before populating the new data? I have given the correct answer of the "STAGE" table in the "LISTS" table as a format reference, please help me complete the other answers. Each of the sections in "LISTS" should be sorted based on data from lowest to highest, secondary sort key is alphabetical A to Z on column C."
[Spreadsheet Path]: spreadsheet/13-1
[Target Sheet]: LISTS
[Target Position]: A3:D32 (Total 120 cells)
[Initial Agent Skill]: "Write Python openpyxl code to manipulate the Excel workbook and satisfy the instruction."
▼
Phase 1 Index Shift & Execution Mismatch (索引偏移与矩阵比对失败)
Sandboxed Code Runner
skillopt/envs/spreadsheet/sandbox.py:85

代码生成器在用 pandas 读取后再写回 openpyxl 时,默认将表头作为数据行写入,导致整张表所有数值下移一行(Off-by-one Error),单元格准确率仅 3.2%。

Failure: Sheet Cell Accuracy = 3.2%
➔ diff
SANDBOX EXECUTION DIFF MISMATCH (116 / 120 Cells Incorrect)
[Code Trace Snippet]:
`df = pd.read_excel('file.xlsx', sheet_name='RANGES')`
`for r_idx, row in df.iterrows(): ws.cell(row=r_idx+3, column=1, value=row[0])`
[Error Diagnostic]: Pandas 0-indexed iterrows caused Header to be placed at A3 instead of A2, shifting all payload data from Row 3 to Row 4!
▼
Phase 2 Coordinate Defensive Reflection (坐标系防御反思与规则变异)
Analyst Error Clustering
skillopt/gradient/analyst.py:240

Analyst 定位到系统性模式:“混用 pandas 与 openpyxl 极易发生 0/1 索引错位。强制要求原生使用 openpyxl 的 1-indexed 坐标,并在写入前做目标边界显式对齐”。

Gradient: Explicit 1-Indexed Coordinate Skill
➔ mutate
MUTATED SPREADSHEET SKILL Skill v0002 Proposal
[Textual Reflection]: "Never rely on automatic dataframe index mapping. Openpyxl coordinates are 1-based (A1 is row 1, col 1). Explicitly map source cell ranges directly to target cell ranges."
[Mutated Skill]:
"### Excel Scripting Rules:
1. Use openpyxl native iterators: `ws.iter_rows(min_row=..., max_row=...)`.
2. Explicitly bind destination starting row/col.
3. Validate that cell A3 receives the first actual data element, NOT the header string."
▼
Phase 3 100% Cell Accuracy Pass (单元格全匹配通过)
Gatekeeper Matrix Verification
skillopt/evaluation/gate.py:102

沙箱中重新运行生成的优化代码,目标区域 A3:D32 包含的所有 120 个单元格数值与类型与官方标准答案 100% 吻合!

Outcome: SUCCESS (Cell Acc = 100.0%)
➔ pass
FINAL RE-ROLLOUT SUCCESS CA: 100% | SR: 1.0 (PERFECT MATCH)
[Evaluation Summary]:
Target Range: LISTS!A3:D32 (120 Cells)
Matched Cells: 120 / 120 (100.0%)
Data Types: Float, String, Formula strings all identical.
Gate Result: ACCEPTED ➔ Saved to outputs/spreadsheet_run/best_skill.md
SECTION 3 表格沙箱工程防御技巧
1. openpyxl 原生公式保持 (Formula Preservation)
读取含公式的单元格时,必须区分 data_only=True(读计算值)与 data_only=False(读原始公式),防止重写时意外清除原有公式。
2. 隔离沙箱超时与死锁熔断 (Timeout Defense)
执行外部大模型生成的复杂 Python 循环时,设置 10 秒硬超时限制,防止死循环耗尽服务器线程。
SECTION 4 结构化数据操纵算法心流

表格数据具有严密的二维网格拓扑。通过将代码执行报错与单元格级别的 Diff 矩阵回传给 Analyst,系统能够把直觉性的自然语言任务精准映射为具备坐标防御的工程代码生成规范。

SECTION 5 SpreadsheetBench 数据契约规范
字段 类型 说明
id string 任务唯一编号。
instruction string 用户自然语言业务指令。
spreadsheet_path path 存放原始 .xlsx 文件的相对路径。
answer_position string 标准答案所在单元格范围(如 A3:D32)。
SECTION 6 SpreadsheetBench 自动化任务排行榜
模型 / 优化方法 Cell Accuracy (CA) Sheet Success Rate (SR)
GPT-4o (Direct Code Gen) 61.5% 38.2%
SkillOpt (Ours - Qwen-2.5-Coder) 79.4% 54.0% (+15.8pp)
SkillOpt (Ours - GPT-4o) 86.2% 67.5% (+29.3pp)