Spreadsheet Workbook Forensics
Use this skill for workbook edits where preserving structure and verifying target cells matters.
Workflow
- Inspect the actual workbook, not only a preview: sheet names, dimensions, merged cells, headers, formulas, named ranges, and nearby examples.
- Locate source tables and destination ranges by labels, headers, surrounding structure, and requested ranges, not fixed coordinates unless explicitly given.
- Write a small script with
INPUT_PATHandOUTPUT_PATHconstants. - Use
openpyxlfor structure-preserving read/write. Usepandasonly for in-memory transformation, then write back withopenpyxl. - Execute the script.
- Reopen the saved workbook and verify representative and boundary target cells.
Workbook Rules
- Preserve unrelated sheets, cells, formulas, formatting, widths, borders, and named ranges.
- Clear only the instructed output range before writing new results.
- Do not insert/delete rows, sort source records, or relocate tables unless explicitly requested.
- Copy style/number format from nearby template rows when adding outputs.
- Delete rows bottom-to-top if deletion is explicitly required.
Formula And Value Rules
openpyxldoes not calculate formulas or update cached formula results.- If the grader or user needs cell values, compute results in Python and write literal values unless live formulas are explicitly required.
- Load a second workbook with
data_only=Truewhen existing formulas are inputs:
wb = openpyxl.load_workbook(INPUT_PATH)
wb_values = openpyxl.load_workbook(INPUT_PATH, data_only=True)
- Treat existing formulas as semantic specifications: referenced ranges, criteria, lookup keys, and error handling should guide the Python computation.
- Do not leave unevaluated formulas in target cells unless the deliverable explicitly asks for formulas.
Matching And Normalization
- Normalize text by trimming, collapsing whitespace/NBSPs, and casefolding.
- Normalize numeric-looking IDs consistently:
330,330.0, and"330"may be the same key when context says so. - Parse numbers after removing currency symbols and commas while preserving signs and decimals.
- Normalize dates deliberately across
datetime, Excel serials, and date-like strings. - Build explicit single or composite keys for joins, lookups, deduplication, grouping, and interval matches.
Output Verification
Before finalizing:
- Run the script once and fix syntax/runtime errors.
- Reopen
OUTPUT_PATH. - Check first, last, blank-sensitive, no-match, total, and representative target rows.
- Confirm expected target cells contain non-formula literals when values are expected.
- Confirm stale formulas or values were cleared from the target range.
- Avoid quoting large raw workbook contents in the final response if cells may contain sensitive text.