Important: All scripts/ paths are relative to this skill directory.
Use run_skill_script tool to execute scripts, or run with: cd {this_skill_dir} && python scripts/...
Requirements for Outputs
All Excel files
Professional Font
- Use a consistent, professional font (e.g., Arial, Times New Roman) unless otherwise instructed
Zero Formula Errors
- Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)
Preserve Existing Templates
- Study and EXACTLY match existing format, style, and conventions when modifying files
- Existing template conventions ALWAYS override these guidelines
Financial Models
Color Coding Standards
- Blue text (0,0,255): Hardcoded inputs
- Black text (0,0,0): ALL formulas and calculations
- Green text (0,128,0): Links from other worksheets
- Red text (255,0,0): External links to other files
- Yellow background (255,255,0): Key assumptions needing attention
Number Formatting Standards
- Years: Format as text strings ("2024" not "2,024")
- Currency: Use $#,##0 format; specify units in headers ("Revenue ($mm)")
- Zeros: Format as "-" including percentages
- Percentages: Default to 0.0% format
- Multiples: Format as 0.0x
- Negative numbers: Use parentheses (123) not minus -123
Formula Construction Rules
- Place ALL assumptions in separate assumption cells
- Use cell references instead of hardcoded values
- Example: Use
=B5*(1+$B$6) instead of =B5*1.05
XLSX creation, editing, and analysis
Prerequisites
- openpyxl: Excel file creation and editing
- pandas: data analysis and bulk operations
- LibreOffice (
soffice): formula recalculation via scripts/recalc.py
CRITICAL: Use Formulas, Not Hardcoded Values
Always use Excel formulas instead of calculating values in Python and hardcoding them.
WRONG - Hardcoding
total = df['Sales'].sum()
sheet['B10'] = total # Bad: hardcodes 5000
CORRECT - Using Formulas
sheet['B10'] = '=SUM(B2:B9)'
Common Workflow
- Choose tool: pandas for data, openpyxl for formulas/formatting
- Create/Load: Create new workbook or load existing file
- Modify: Add/edit data, formulas, and formatting
- Save: Write to file
- Recalculate formulas (MANDATORY IF USING FORMULAS):
python scripts/recalc.py output.xlsx
- Verify and fix any errors:
- If
status is errors_found, check error_summary for specific errors
- Fix the identified errors and recalculate again
Reading and Analyzing Data
Data analysis with pandas
import pandas as pd
df = pd.read_excel('file.xlsx') # Default: first sheet
all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict
df.head() # Preview data
df.info() # Column info
df.describe() # Statistics
df.to_excel('output.xlsx', index=False)
Excel File Workflows
Creating new Excel files
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = Workbook()
sheet = wb.active
sheet['A1'] = 'Hello'
sheet['B1'] = 'World'
sheet.append(['Row', 'of', 'data'])
sheet['B2'] = '=SUM(A1:A10)'
sheet['A1'].font = Font(bold=True, color='FF0000')
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')
sheet.column_dimensions['A'].width = 20
wb.save('output.xlsx')
Editing existing Excel files
from openpyxl import load_workbook
wb = load_workbook('existing.xlsx')
sheet = wb.active
sheet['A1'] = 'New Value'
sheet.insert_rows(2)
sheet.delete_cols(3)
new_sheet = wb.create_sheet('NewSheet')
new_sheet['A1'] = 'Data'
wb.save('modified.xlsx')
Unpack/Pack Workflow (Advanced XML editing)
For advanced Excel manipulation via raw XML:
# Unpack
python scripts/office/unpack.py spreadsheet.xlsx unpacked/
# Edit XML in unpacked/xl/worksheets/, unpacked/xl/sharedStrings.xml, etc.
# Pack
python scripts/office/pack.py unpacked/ output.xlsx
Recalculating Formulas
python scripts/recalc.py <excel_file> [timeout_seconds]
The script:
- Automatically sets up LibreOffice macro on first run
- Recalculates all formulas in all sheets
- Scans ALL cells for Excel errors
- Returns JSON with detailed error locations and counts
- Works on Linux, macOS, and Windows
Interpreting recalc.py Output
{
"status": "success",
"total_errors": 0,
"total_formulas": 42,
"error_summary": {}
}
Formula Verification Checklist
Essential Verification
- Test 2-3 sample references before building full model
- Confirm Excel column mapping (column 64 = BL, not BK)
- Remember Excel rows are 1-indexed (DataFrame row 5 = Excel row 6)
Common Pitfalls
- NaN handling: Check for null values with
pd.notna()
- Division by zero: Check denominators before
/ in formulas
- Wrong references: Verify all cell references point to intended cells
- Cross-sheet references: Use correct format (
Sheet1!A1)
Best Practices
Library Selection
- pandas: Best for data analysis, bulk operations, and simple data export
- openpyxl: Best for complex formatting, formulas, and Excel-specific features
Working with openpyxl
- Cell indices are 1-based
- Use
data_only=True to read calculated values
- Warning:
data_only=True + save = formulas permanently lost
- Formulas are preserved but not evaluated - use
scripts/recalc.py to update values
1---2name: xlsx3description: Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .csv, or .tsv file; create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Also trigger for cleaning or restructuring messy tabular data. The deliverable must be a spreadsheet file.4---56> **Important:** All `scripts/` paths are relative to this skill directory.7> Use `run_skill_script` tool to execute scripts, or run with: `cd {this_skill_dir} && python scripts/...`89# Requirements for Outputs1011## All Excel files1213### Professional Font14- Use a consistent, professional font (e.g., Arial, Times New Roman) unless otherwise instructed1516### Zero Formula Errors17- Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)1819### Preserve Existing Templates20- Study and EXACTLY match existing format, style, and conventions when modifying files21- Existing template conventions ALWAYS override these guidelines2223## Financial Models2425### Color Coding Standards2627- **Blue text (0,0,255)**: Hardcoded inputs28- **Black text (0,0,0)**: ALL formulas and calculations29- **Green text (0,128,0)**: Links from other worksheets30- **Red text (255,0,0)**: External links to other files31- **Yellow background (255,255,0)**: Key assumptions needing attention3233### Number Formatting Standards3435- **Years**: Format as text strings ("2024" not "2,024")36- **Currency**: Use $#,##0 format; specify units in headers ("Revenue ($mm)")37- **Zeros**: Format as "-" including percentages38- **Percentages**: Default to 0.0% format39- **Multiples**: Format as 0.0x40- **Negative numbers**: Use parentheses (123) not minus -1234142### Formula Construction Rules4344- Place ALL assumptions in separate assumption cells45- Use cell references instead of hardcoded values46- Example: Use `=B5*(1+$B$6)` instead of `=B5*1.05`4748# XLSX creation, editing, and analysis4950## Prerequisites5152- **openpyxl**: Excel file creation and editing53- **pandas**: data analysis and bulk operations54- **LibreOffice** (`soffice`): formula recalculation via `scripts/recalc.py`5556## CRITICAL: Use Formulas, Not Hardcoded Values5758**Always use Excel formulas instead of calculating values in Python and hardcoding them.**5960### WRONG - Hardcoding61```python62total = df['Sales'].sum()63sheet['B10'] = total # Bad: hardcodes 500064```6566### CORRECT - Using Formulas67```python68sheet['B10'] = '=SUM(B2:B9)'69```7071## Common Workflow72731. **Choose tool**: pandas for data, openpyxl for formulas/formatting742. **Create/Load**: Create new workbook or load existing file753. **Modify**: Add/edit data, formulas, and formatting764. **Save**: Write to file775. **Recalculate formulas (MANDATORY IF USING FORMULAS)**:78 ```bash79 python scripts/recalc.py output.xlsx80 ```816. **Verify and fix any errors**:82 - If `status` is `errors_found`, check `error_summary` for specific errors83 - Fix the identified errors and recalculate again8485## Reading and Analyzing Data8687### Data analysis with pandas88```python89import pandas as pd9091df = pd.read_excel('file.xlsx') # Default: first sheet92all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict9394df.head() # Preview data95df.info() # Column info96df.describe() # Statistics9798df.to_excel('output.xlsx', index=False)99```100101## Excel File Workflows102103### Creating new Excel files104```python105from openpyxl import Workbook106from openpyxl.styles import Font, PatternFill, Alignment107108wb = Workbook()109sheet = wb.active110111sheet['A1'] = 'Hello'112sheet['B1'] = 'World'113sheet.append(['Row', 'of', 'data'])114115sheet['B2'] = '=SUM(A1:A10)'116117sheet['A1'].font = Font(bold=True, color='FF0000')118sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')119sheet['A1'].alignment = Alignment(horizontal='center')120121sheet.column_dimensions['A'].width = 20122123wb.save('output.xlsx')124```125126### Editing existing Excel files127```python128from openpyxl import load_workbook129130wb = load_workbook('existing.xlsx')131sheet = wb.active132133sheet['A1'] = 'New Value'134sheet.insert_rows(2)135sheet.delete_cols(3)136137new_sheet = wb.create_sheet('NewSheet')138new_sheet['A1'] = 'Data'139140wb.save('modified.xlsx')141```142143## Unpack/Pack Workflow (Advanced XML editing)144145For advanced Excel manipulation via raw XML:146147```bash148# Unpack149python scripts/office/unpack.py spreadsheet.xlsx unpacked/150151# Edit XML in unpacked/xl/worksheets/, unpacked/xl/sharedStrings.xml, etc.152153# Pack154python scripts/office/pack.py unpacked/ output.xlsx155```156157## Recalculating Formulas158159```bash160python scripts/recalc.py <excel_file> [timeout_seconds]161```162163The script:164- Automatically sets up LibreOffice macro on first run165- Recalculates all formulas in all sheets166- Scans ALL cells for Excel errors167- Returns JSON with detailed error locations and counts168- Works on Linux, macOS, and Windows169170### Interpreting recalc.py Output171```json172{173 "status": "success",174 "total_errors": 0,175 "total_formulas": 42,176 "error_summary": {}177}178```179180## Formula Verification Checklist181182### Essential Verification183- Test 2-3 sample references before building full model184- Confirm Excel column mapping (column 64 = BL, not BK)185- Remember Excel rows are 1-indexed (DataFrame row 5 = Excel row 6)186187### Common Pitfalls188- NaN handling: Check for null values with `pd.notna()`189- Division by zero: Check denominators before `/` in formulas190- Wrong references: Verify all cell references point to intended cells191- Cross-sheet references: Use correct format (`Sheet1!A1`)192193## Best Practices194195### Library Selection196- **pandas**: Best for data analysis, bulk operations, and simple data export197- **openpyxl**: Best for complex formatting, formulas, and Excel-specific features198199### Working with openpyxl200- Cell indices are 1-based201- Use `data_only=True` to read calculated values202- **Warning**: `data_only=True` + save = formulas permanently lost203- Formulas are preserved but not evaluated - use `scripts/recalc.py` to update values