--- name: xlsx description: Reads, explains, builds and repairs Excel (.xlsx) workbooks, including tracing formulas, writing new formulas from plain-English descriptions, combining tabs and flagging inconsistencies. Use when a user says "explain this spreadsheet", "what drives this cell", "write a formula for", "merge these tabs", "why is this total wrong", or attaches an Excel file. --- # Excel Spreadsheets Treats a workbook as a small program: inputs, calculations and outputs. Understand how it is wired before explaining or changing it, and never break what already works. ## When to use this - The user inherits a workbook and needs to know what is in it and how it calculates. - The user wants a formula, a summary tab, a pivot-style table or a combined dataset. - A number looks wrong and someone needs to find out why. - A new tracker, model or report needs building as an .xlsx file. ## Procedure 1. **Clarify the goal.** One question: understand, fix, extend or create? For edits, ask which cells or tabs are off limits. 2. **Map the workbook first.** With openpyxl or an equivalent, list every sheet with its used range, hidden state, named ranges, external links, data validations, merged cells and whether macros are present. Present this as a compact inventory table. 3. **Read formulas and values separately.** Load the file twice: once to see the formula text, once with cached values, so you can show both what a cell computes and what it currently shows. Note any cells where the cached value is missing or stale. 4. **Classify each sheet's role.** Label sheets as raw input, working calculation, lookup table or output report. Say which cells are hard-coded inputs and which are formulas, since hard-coded numbers buried inside formulas are the usual source of silent errors. 5. **Trace on demand.** For a question like "what drives this total?", walk the precedents back to inputs and describe the chain in plain English, with cell references in parentheses. Stop at inputs and say which of them are assumptions. 6. **Audit quickly.** Check for error values, formulas that differ from their neighbors in a column, ranges that stop short of the data, mixed units, numbers stored as text, circular references and volatile functions. Report findings in a table with location, issue and suggested fix. 7. **Write formulas for the user's real layout.** Restate the requirement, reference actual headers and ranges, prefer structured or absolute references where they prevent drift, and avoid fragile nesting. Provide one worked example row and the expected result so the user can verify. 8. **Combining tabs.** Compare headers across tabs first and report mismatches before merging. Add a source-tab column, keep types consistent, and reconcile row totals against the originals. 9. **Building new workbooks.** Separate inputs, calculations and outputs onto different areas or sheets, label inputs clearly, use formulas rather than pasted values, add basic validation, freeze header rows and set readable number formats. 10. **Save safely and verify.** Write to a new filename. Recalculate if an engine such as LibreOffice is available, then confirm there are no error values and that key totals match expectations. ## Output format - For explanations: a short narrative of what the workbook does, followed by the sheet inventory table and a list of risks. - For formulas: the formula in a code block, a one-line explanation, and a test example. - For files: saved path plus a change log listing every sheet and range modified. ## Quality checks Before delivering, confirm each of these: - Totals recalculate to the same figures after saving and reopening. - No formula points at an empty range or at a hidden row by accident. - Hard-coded constants live in labeled input cells, not inside formulas. - Row counts after any merge equal the sum of the source tabs. - Formats show the right units, decimals and date style. - The change log names every sheet and range you touched. ## Guardrails - Never overwrite the original workbook, and never delete sheets, rows or hidden content without being asked. - Report macros and what their code appears to do, but do not run them. - Do not guess at business meaning of a number; say what the cells compute and ask what it represents. - Be explicit about limits when a file is too large to process in one pass and describe how you split it. - Keep confidential figures out of examples and summaries beyond what the user needs.