excel-openpyxl-formulas

excel-openpyxl-formulas is a skill for Claude Code, Codex from cxcscmu/SkillLearnBench. It costs 30 tokens per session (928 once invoked), scanned A, original, MIT.

A Python guide for editing Excel workbooks with openpyxl, including adding formulas while keeping existing formatting and structure intact.

In plain words
What is it for?
Use it to add one formula or fill a range of cells with related formulas in an existing .xlsx file.
Why use it?
It helps avoid losing formulas, styles, colors, or layout when a workbook is saved after automated edits.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cxcscmu/skilllearnbench/excel-openpyxl-formulas
Any agent
npx skills add cxcscmu/SkillLearnBench --skill excel-openpyxl-formulas
Clone the repo
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for excel-openpyxl-formulas

README.md
[![agentmods](https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/excel-openpyxl-formulas.svg)](https://agentmods.dev/skills/cxcscmu/skilllearnbench/excel-openpyxl-formulas)
Your own site
<a href="https://agentmods.dev/skills/cxcscmu/skilllearnbench/excel-openpyxl-formulas"><img src="https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/excel-openpyxl-formulas.svg" alt="Measured on agentmods" height="20"></a>
Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 928 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00030 $0.00928
Opus 5 $0.00015 $0.00464
Sonnet 5 $0.00006 $0.00186
Haiku 4.5 $0.00003 $0.00093

Measured 2d ago against content hash 99b72549969c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

excel-openpyxl-formulas scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/b1-one-shot-claude-sonnet-4-6/weighted-gdp-calculation/excel-openpyxl-formulas/SKILL.md · 115 lines

How it starts

The opening of the file, as written. The whole thing — 115 lines — stays where its author put it; the contents beside it link to each section on GitHub.

openpyxl: Insert Formulas While Preserving Formatting

Critical Rule: Load Without data_only

from openpyxl import load_workbook

# CORRECT: preserves formulas and formatting
wb = load_workbook('file.xlsx')

# WRONG: replaces formulas with cached values on save
wb = load_workbook('file.xlsx', data_only=True)

Basic Formula Insertion

wb = load_workbook('file.xlsx')
ws = wb['Sheet1']

ws['H12'] = '=INDEX(Data!$H$21:$M$40,MATCH($D12,Data!$B$21:$B$40,0),MATCH(H$10,Data!$H$4:$M$4,0))'

wb.save('file.xlsx')

Iterating Over Cell Ranges

When applying similar formulas to a grid of cells, iterate using row/column indices:

from openpyxl.utils import get_column_letter

# Fill a range (e.g., H12:L17) with formulas
start_row = 12
end_row = 17
start_col = 8   # H = column 8
end_col = 12    # L = column 12

for row in range(start_row, end_row + 1):
    for col in range(start_col, end_col + 1):
        col_letter = get_column_letter(col)
        cell = ws.cell(row=row, column=col)
        cell.value = f'=INDEX(Data!$I$21:$M$40,MATCH($D{row},Data!$B$21:$B$40,0),MATCH({col_letter}$10,Data!$I$4:$M$4,0))'

Preserving Cell Formatting

openpyxl preserves existing cell styles when you only change value. Setting a new value does NOT erase fill color, font, borders, etc.:

cell = ws['H12']
cell.value = '=SUM(A1:A10)'  # Only changes the value; style is preserved

Row and Column Reference Conversion

from openpyxl.utils import get_column_letter, column_index_from_string

get_column_letter(8)    # → 'H'
get_column_letter(12)   # → 'L'
column_index_from_string('H')  # → 8
column_index_from_string('L')  # → 12

Recalculating Formulas After Editing

After saving, run recalc.py to update cached formula values:

python recalc.py file.xlsx

Check output for errors:

{"status": "success", "total_errors": 0, "total_formulas": 42}

If errors found:

{"status": "errors_found", "error_summary": {"#REF!": {"count": 2, "locations": ["Task!H12"]}}}

Read the full file on GitHub · 115 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 115 lines · 30 tokens per session scan A 99b72549969c

Subscribe to this mod's changes

excel-openpyxl-formulas is a skill published in the GitHub repository cxcscmu/SkillLearnBench (83 stars, last pushed 1mo ago), licensed MIT. It adds 30 tokens to every session and 928 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.