SpreadsheetBench: 真实复杂电子表格操作基准与 Agent 优化全景
展现智能体在面对真实业务表格时的端到端拓扑。输入包括多工作表(Sheets)、公式逻辑与自然语言业务指令。系统通过生成 Python/openpyxl 脚本在隔离沙箱中执行,与真实 Excel 预期单元格区域(Answer Position)比对,基于执行报错与数值差异进行策略退火更新。
spreadsheetbench_verified_400/• 真实 .xlsx 业务工作薄
Cell-Level, Sheet-Level, Cross-Table Lookup
标准答案工作表 + 单元格边界(如 A3:D32)
Agent 生成 openpyxl 代码
在隔离沙箱中加载并修改表格
逐单元格对比数值与公式
捕获行列偏移与类型错位
反思索引错位(0-index vs 1-index)
优化跨表 VLOOKUP 策略
严格单元格精确率验证
必须 100% 匹配目标区域
匹配单元格数量 / 目标总格数
整张表完全吻合的严格通过率
outputs/spreadsheet_run/best_skill.md
对齐展示 SpreadsheetBench 官方 Verified 第一条真实样本(id: 13-1,关于跨多工作表数据去重合并的任务)。
加载 spreadsheet/13-1 原始文件,解析元数据:要求将 'RANGES' 表格数据合并至 'LISTS' 表,并写入目标区域。
[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."
代码生成器在用 pandas 读取后再写回 openpyxl 时,默认将表头作为数据行写入,导致整张表所有数值下移一行(Off-by-one Error),单元格准确率仅 3.2%。
[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!
Analyst 定位到系统性模式:“混用 pandas 与 openpyxl 极易发生 0/1 索引错位。强制要求原生使用 openpyxl 的 1-indexed 坐标,并在写入前做目标边界显式对齐”。
[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."
沙箱中重新运行生成的优化代码,目标区域 A3:D32 包含的所有 120 个单元格数值与类型与官方标准答案 100% 吻合!
[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
读取含公式的单元格时,必须区分
data_only=True(读计算值)与 data_only=False(读原始公式),防止重写时意外清除原有公式。
执行外部大模型生成的复杂 Python 循环时,设置 10 秒硬超时限制,防止死循环耗尽服务器线程。
表格数据具有严密的二维网格拓扑。通过将代码执行报错与单元格级别的 Diff 矩阵回传给 Analyst,系统能够把直觉性的自然语言任务精准映射为具备坐标防御的工程代码生成规范。
| 字段 | 类型 | 说明 |
|---|---|---|
id |
string |
任务唯一编号。 |
instruction |
string |
用户自然语言业务指令。 |
spreadsheet_path |
path |
存放原始 .xlsx 文件的相对路径。 |
answer_position |
string |
标准答案所在单元格范围(如 A3:D32)。 |
| 模型 / 优化方法 | 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) |