Excel Python
Engineer Excel files from an explicit workbook contract. Preserve package
semantics, distinguish stored artifacts from Excel-runtime behavior, mutate the
smallest supported region, and prove the result by independent reopening and a
semantic comparison.
Boundary and ownership
| Required semantics |
Owner |
Rule |
| Workbook/package structure, formulas, Tables, names, styles, charts, preservation |
excel-python |
Inspect OOXML and use openpyxl or XlsxWriter deliberately. |
| Tabular extraction only |
Polars read_excel with Calamine when installed |
Use when workbook layout is merely an input boundary. |
| Joins, aggregation, dtypes, nulls, lazy plans, analytical computation |
polars-python |
Hand off dataframe decisions; return only for workbook delivery. |
| Recalculation, refresh, native PDF/rendering, authorized VBA, unsupported Excel objects |
installed-Excel runtime workflow |
Stop and escalate; this skill never simulates Excel. |
Inspect installed APIs before relying on drift-prone behavior. Run
python scripts/inspect_excel_env.py from the installed skill and read
library selection.
Ordered workflow
- Recover the workbook contract from the request, workbook, callers, and
downstream consumers. State sheet roles, Tables and names, row grain, keys,
units, input/output regions, formula-owned columns, editable areas,
presentation areas, compatibility, preservation, calculation, and delivery
requirements. Prefer
cell < range < defined name < Excel Table < workbook contract; use bare addresses only when no stable interface exists. Read
workbook contracts.
- Preserve the source. Resolve extension, output destination, trust boundary,
workbook date system, macros, links, and features that must survive.
- Before editing a valuable workbook, run
python scripts/inspect_workbook.py INPUT.xlsx. Treat its JSON as preflight evidence,
not proof that openpyxl can preserve every reported part. Unknown or
unsupported OOXML plus a preservation requirement blocks a blind round-trip.
- Choose the operation path: Polars/Calamine for table extraction, openpyxl
for supported existing-workbook inspection or minimal mutation, and
XlsxWriter or Polars
write_excel for new workbooks. Read ingestion,
existing workbooks, or
generation.
- Apply explicit type and precision,
formula, and untrusted text
policies before writing.
- Write to a temporary sibling, close successfully, then reopen independently.
For edits, run
python scripts/diff_workbooks.py BEFORE AFTER; classify each
difference as required, acceptable serialization variation, or unexpected.
- Run contract assertions and relevant project tests. For stakeholder output,
render or inspect representative sheets because valid OOXML can be unusable.
Read semantic validation.
Workbook contract invariants
- A cell format changes display, not stored arithmetic. Identifiers that can
exceed 15 significant digits are text. Exact rounding is a value operation,
not a number format. Define blank, empty string,
NaN, infinity, boolean,
date, datetime, timezone, currency, percentage, and basis-point policy.
- Preserve the 1900/1904 date system. Do not transfer raw serials across date
systems without conversion and verification.
- Formula text, cached value, and Excel-engine recalculation are three evidence
states:
FORMULA_TEXT_CHECKED, CACHE_INSPECTED, and RECALCULATED. Claim
only states actually established.
- XlsxWriter stores formulas in US-English syntax. It does not calculate them;
absent an explicit result it stores zero and requests recalculation on open.
- Externally sourced text is text. Do not allow leading
= or URL-like data to
become formulas or hyperlinks implicitly; use write_string() or disable
strings_to_formulas and strings_to_urls for text-first exports.
- For
.xlsm, use keep_vba=True, preserve the macro-enabled extension, never
execute VBA, and compare the VBA project hash before and after.
- Never execute macros, refresh connections, claim remote link freshness, or
claim Excel recalculation from an openpyxl/XlsxWriter save.
Preservation and scale gates
Inspect ZIP parts and relationships for VBA, drawings/shapes, charts,
chartsheets, pivots and caches, slicers, external links, connections/Power
Query artifacts, custom XML, embeddings, ActiveX/forms, comments/threaded
comments, media, custom properties, and unknown relationships. If a required
feature is unsupported or preservation is unknown, do not save with openpyxl;
retain the original and require an authorized Excel-native path. Read
OOXML preservation.
Fail before exceeding 1,048,576 rows or 16,384 columns per worksheet. Prefer a
summarized Excel view with Parquet/DuckDB/Polars for oversized analytical data.
XlsxWriter constant_memory requires sequential rows and disables Tables and
merged ranges; choose features before memory mode. openpyxl read-only/write-only
modes also omit normal APIs. Read performance and limits.
Generated workbook quality
Keep machine-readable raw data separate from presentation sheets. Use named
Tables, visible units, centralized number formats, filters, useful freeze panes,
clear input/formula/output styling, stable chart sources, labeled axes, sensible
widths, and no merged cells inside data regions. Use hidden sheets only when
their role is documented in the contract. Add an optional _meta or About
section when provenance matters: generator/schema version, generation and
as-of timestamps, source identifiers or hashes, parameters, and code revision.
Read presentation.
Completion
Do not declare completion until the source remains intact; preflight risks are
resolved; the output reopens; sheet/name/Table/formula/type/date/visibility and
selected style/value contracts pass; required VBA and high-risk package parts
are unchanged; the semantic diff contains no unexplained differences; visual
review ran when presentation is contractual; and recalculation/runtime evidence
is reported separately. Use evaluated recipes only
for their stated conditions.
References
- Library selection and adjacent-skill routing
- Workbook contracts
- Tabular ingestion
- Types and precision
- Formula semantics
- Inspection
- OOXML preservation
- Existing-workbook mutation
- Generation
- Presentation and provenance
- Performance and Excel limits
- Untrusted text and security
- Semantic validation and testing
- Evaluated core recipes
1---2name: excel-python3description: Use for writing, reviewing, debugging, or testing Python code that inspects, edits, extracts, validates, preserves, or generates Excel .xlsx or .xlsm workbooks. Trigger on workbook contracts, formulas and cached values, Excel Tables, defined names, OOXML parts, types and precision, macros, charts, hidden sheets, external links, and semantic workbook verification. Do not use for CSV-only work, dataframe computation with no workbook boundary, Excel UI automation, recalculation, connection refresh, or macro execution.4---56# Excel Python78Engineer Excel files from an explicit workbook contract. Preserve package9semantics, distinguish stored artifacts from Excel-runtime behavior, mutate the10smallest supported region, and prove the result by independent reopening and a11semantic comparison.1213## Boundary and ownership1415| Required semantics | Owner | Rule |16|---|---|---|17| Workbook/package structure, formulas, Tables, names, styles, charts, preservation | `excel-python` | Inspect OOXML and use openpyxl or XlsxWriter deliberately. |18| Tabular extraction only | Polars `read_excel` with Calamine when installed | Use when workbook layout is merely an input boundary. |19| Joins, aggregation, dtypes, nulls, lazy plans, analytical computation | `polars-python` | Hand off dataframe decisions; return only for workbook delivery. |20| Recalculation, refresh, native PDF/rendering, authorized VBA, unsupported Excel objects | installed-Excel runtime workflow | Stop and escalate; this skill never simulates Excel. |2122Inspect installed APIs before relying on drift-prone behavior. Run23`python scripts/inspect_excel_env.py` from the installed skill and read24[library selection](references/library-selection.md).2526## Ordered workflow27281. Recover the workbook contract from the request, workbook, callers, and29 downstream consumers. State sheet roles, Tables and names, row grain, keys,30 units, input/output regions, formula-owned columns, editable areas,31 presentation areas, compatibility, preservation, calculation, and delivery32 requirements. Prefer `cell < range < defined name < Excel Table < workbook33 contract`; use bare addresses only when no stable interface exists. Read34 [workbook contracts](references/workbook-contracts.md).352. Preserve the source. Resolve extension, output destination, trust boundary,36 workbook date system, macros, links, and features that must survive.373. Before editing a valuable workbook, run `python38 scripts/inspect_workbook.py INPUT.xlsx`. Treat its JSON as preflight evidence,39 not proof that openpyxl can preserve every reported part. Unknown or40 unsupported OOXML plus a preservation requirement blocks a blind round-trip.414. Choose the operation path: Polars/Calamine for table extraction, openpyxl42 for supported existing-workbook inspection or minimal mutation, and43 XlsxWriter or Polars `write_excel` for new workbooks. Read [ingestion](references/ingestion.md),44 [existing workbooks](references/existing-workbooks.md), or45 [generation](references/generation.md).465. Apply explicit [type and precision](references/types-and-precision.md),47 [formula](references/formulas.md), and [untrusted text](references/security.md)48 policies before writing.496. Write to a temporary sibling, close successfully, then reopen independently.50 For edits, run `python scripts/diff_workbooks.py BEFORE AFTER`; classify each51 difference as required, acceptable serialization variation, or unexpected.527. Run contract assertions and relevant project tests. For stakeholder output,53 render or inspect representative sheets because valid OOXML can be unusable.54 Read [semantic validation](references/validation-testing.md).5556## Workbook contract invariants5758- A cell format changes display, not stored arithmetic. Identifiers that can59 exceed 15 significant digits are text. Exact rounding is a value operation,60 not a number format. Define blank, empty string, `NaN`, infinity, boolean,61 date, datetime, timezone, currency, percentage, and basis-point policy.62- Preserve the 1900/1904 date system. Do not transfer raw serials across date63 systems without conversion and verification.64- Formula text, cached value, and Excel-engine recalculation are three evidence65 states: `FORMULA_TEXT_CHECKED`, `CACHE_INSPECTED`, and `RECALCULATED`. Claim66 only states actually established.67- XlsxWriter stores formulas in US-English syntax. It does not calculate them;68 absent an explicit result it stores zero and requests recalculation on open.69- Externally sourced text is text. Do not allow leading `=` or URL-like data to70 become formulas or hyperlinks implicitly; use `write_string()` or disable71 `strings_to_formulas` and `strings_to_urls` for text-first exports.72- For `.xlsm`, use `keep_vba=True`, preserve the macro-enabled extension, never73 execute VBA, and compare the VBA project hash before and after.74- Never execute macros, refresh connections, claim remote link freshness, or75 claim Excel recalculation from an openpyxl/XlsxWriter save.7677## Preservation and scale gates7879Inspect ZIP parts and relationships for VBA, drawings/shapes, charts,80chartsheets, pivots and caches, slicers, external links, connections/Power81Query artifacts, custom XML, embeddings, ActiveX/forms, comments/threaded82comments, media, custom properties, and unknown relationships. If a required83feature is unsupported or preservation is unknown, do not save with openpyxl;84retain the original and require an authorized Excel-native path. Read85[OOXML preservation](references/ooxml-preservation.md).8687Fail before exceeding 1,048,576 rows or 16,384 columns per worksheet. Prefer a88summarized Excel view with Parquet/DuckDB/Polars for oversized analytical data.89XlsxWriter `constant_memory` requires sequential rows and disables Tables and90merged ranges; choose features before memory mode. openpyxl read-only/write-only91modes also omit normal APIs. Read [performance and limits](references/performance.md).9293## Generated workbook quality9495Keep machine-readable raw data separate from presentation sheets. Use named96Tables, visible units, centralized number formats, filters, useful freeze panes,97clear input/formula/output styling, stable chart sources, labeled axes, sensible98widths, and no merged cells inside data regions. Use hidden sheets only when99their role is documented in the contract. Add an optional `_meta` or About100section when provenance matters: generator/schema version, generation and101as-of timestamps, source identifiers or hashes, parameters, and code revision.102Read [presentation](references/presentation.md).103104## Completion105106Do not declare completion until the source remains intact; preflight risks are107resolved; the output reopens; sheet/name/Table/formula/type/date/visibility and108selected style/value contracts pass; required VBA and high-risk package parts109are unchanged; the semantic diff contains no unexplained differences; visual110review ran when presentation is contractual; and recalculation/runtime evidence111is reported separately. Use [evaluated recipes](references/recipes-core.md) only112for their stated conditions.113114## References115116- [Library selection and adjacent-skill routing](references/library-selection.md)117- [Workbook contracts](references/workbook-contracts.md)118- [Tabular ingestion](references/ingestion.md)119- [Types and precision](references/types-and-precision.md)120- [Formula semantics](references/formulas.md)121- [Inspection](references/inspection.md)122- [OOXML preservation](references/ooxml-preservation.md)123- [Existing-workbook mutation](references/existing-workbooks.md)124- [Generation](references/generation.md)125- [Presentation and provenance](references/presentation.md)126- [Performance and Excel limits](references/performance.md)127- [Untrusted text and security](references/security.md)128- [Semantic validation and testing](references/validation-testing.md)129- [Evaluated core recipes](references/recipes-core.md)