@yeongjaeyou/claude-code-config 0.9.2 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,16 +5,20 @@ Break down large work items into manageable, independent issues. Follow project
|
|
|
5
5
|
## Workflow
|
|
6
6
|
|
|
7
7
|
1. Check issue numbers: Run `gh issue list` to view current issue numbers
|
|
8
|
-
2.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
2. **Discover available components**:
|
|
9
|
+
- Scan `.claude/agents/` for custom agents (read YAML frontmatter)
|
|
10
|
+
- Scan `.claude/skills/` for available skills (read SKILL.md)
|
|
11
|
+
- Check `.mcp.json` for configured MCP servers
|
|
12
|
+
3. Analyze work: Understand core requirements and objectives
|
|
13
|
+
4. Decompose work: Split major tasks into smaller, manageable sub-tasks or issues. **Aim for optimal count over excessive issues (keep it manageable)**
|
|
14
|
+
5. Analyze dependencies: Identify prerequisite tasks
|
|
15
|
+
6. Suggest milestone name: Propose a milestone to group decomposed tasks
|
|
16
|
+
7. Check related PRs (optional): Run `gh pr list --state closed --limit 20` for similar work references (skip if none)
|
|
17
|
+
8. Output decomposed issues: Display issues with proposed milestone name
|
|
18
|
+
9. Ask about GitHub creation: Use AskUserQuestion to let user decide on milestone and issue creation
|
|
15
19
|
- Create milestone: `gh api repos/:owner/:repo/milestones -f title="Milestone Name" -f description="Description"`
|
|
16
20
|
- Assign issues with `--milestone` option
|
|
17
|
-
|
|
21
|
+
10. **Add issues to GitHub Project (optional)**
|
|
18
22
|
- Check for existing projects: `gh project list --owner <owner> --format json`
|
|
19
23
|
- If no project exists: Display "No project found. You can create one with `/gh:init-project`" and skip
|
|
20
24
|
- If project exists: Ask user via AskUserQuestion whether to add issues
|
|
@@ -58,9 +62,99 @@ Examples (vary by project, for reference only):
|
|
|
58
62
|
**Dependencies**:
|
|
59
63
|
- [ ] None or prerequisite issue #number
|
|
60
64
|
|
|
61
|
-
**
|
|
62
|
-
-
|
|
65
|
+
**Execution strategy**:
|
|
66
|
+
- **Pattern**: main-only | sequential | parallel | delegation
|
|
67
|
+
- **Delegate to**: (delegation only) agent name
|
|
68
|
+
- **Skills**: [discovered skills, or none]
|
|
69
|
+
- **MCP**: [discovered MCP servers, or none]
|
|
70
|
+
|
|
71
|
+
**Execution diagram**:
|
|
72
|
+
```
|
|
73
|
+
+------+
|
|
74
|
+
| main |
|
|
75
|
+
+------+
|
|
76
|
+
Skills: none
|
|
77
|
+
MCP: none
|
|
78
|
+
```
|
|
63
79
|
|
|
64
80
|
**References** (optional):
|
|
65
81
|
- Add related PRs if available (e.g., PR #36 - brief description)
|
|
66
82
|
- Omit this section if none
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Execution Strategy Guide
|
|
87
|
+
|
|
88
|
+
### Component Discovery
|
|
89
|
+
|
|
90
|
+
Before decomposing issues, scan for available components:
|
|
91
|
+
- **Agents**: `.claude/agents/*.md` (extract name, description from YAML frontmatter)
|
|
92
|
+
- **Skills**: `.claude/skills/*/SKILL.md` (extract name, description from YAML frontmatter)
|
|
93
|
+
- **MCP**: `.mcp.json` (extract server names and purposes)
|
|
94
|
+
|
|
95
|
+
### Execution Patterns
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
Pattern A: main-only
|
|
99
|
+
+------+ Skills: /code-explorer, /xlsx
|
|
100
|
+
| main | MCP: serena, context7
|
|
101
|
+
+------+
|
|
102
|
+
|
|
103
|
+
Pattern B: sequential
|
|
104
|
+
+---------+ +------+ Skills: ...
|
|
105
|
+
| explore | --> | main | MCP: ...
|
|
106
|
+
+---------+ +------+
|
|
107
|
+
|
|
108
|
+
Pattern C: parallel
|
|
109
|
+
+---------+
|
|
110
|
+
| explore |--+
|
|
111
|
+
+---------+ | +------+ Skills: ...
|
|
112
|
+
| explore |--+->| main | MCP: ...
|
|
113
|
+
+---------+ | +------+
|
|
114
|
+
| explore |--+
|
|
115
|
+
+---------+
|
|
116
|
+
|
|
117
|
+
Pattern D: delegation
|
|
118
|
+
+------+ +----------------+ Skills: ...
|
|
119
|
+
| main | --> | python-pro | MCP: serena
|
|
120
|
+
+------+ | web-researcher |
|
|
121
|
+
+----------------+
|
|
122
|
+
|
|
123
|
+
Note: main can spawn subagents at any point during execution
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Pattern Selection
|
|
127
|
+
|
|
128
|
+
| Situation | Pattern | Example |
|
|
129
|
+
|-----------|---------|---------|
|
|
130
|
+
| Simple fix/change | main-only | Bug fix, single file change |
|
|
131
|
+
| Analysis then implement | sequential | New feature, refactoring |
|
|
132
|
+
| Complex analysis needed | parallel | Large refactor, architecture change |
|
|
133
|
+
| Specialized work | delegation | Python optimization, technical research |
|
|
134
|
+
|
|
135
|
+
### Diagram in Issues
|
|
136
|
+
|
|
137
|
+
Always include an ASCII diagram in the issue body to visualize the execution flow:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
// main-only
|
|
141
|
+
+------+
|
|
142
|
+
| main |
|
|
143
|
+
+------+
|
|
144
|
+
Skills: /code-review
|
|
145
|
+
MCP: serena
|
|
146
|
+
|
|
147
|
+
// delegation
|
|
148
|
+
+------+ +--------------------+
|
|
149
|
+
| main | --> | deepfake-cv-expert |
|
|
150
|
+
+------+ +--------------------+
|
|
151
|
+
Skills: none
|
|
152
|
+
MCP: none
|
|
153
|
+
|
|
154
|
+
// sequential
|
|
155
|
+
+---------+ +------+
|
|
156
|
+
| explore | --> | main |
|
|
157
|
+
+---------+ +------+
|
|
158
|
+
Skills: ...
|
|
159
|
+
MCP: ...
|
|
160
|
+
```
|
|
@@ -61,17 +61,34 @@ Utilize MCP servers whenever possible:
|
|
|
61
61
|
- `mcpdocs` - Documentation fetching
|
|
62
62
|
- `firecrawl` - Web scraping and search
|
|
63
63
|
|
|
64
|
-
###
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
### Agent & Skill Usage
|
|
65
|
+
- 작업에 적합한 agent 또는 skill이 있다면 적극 활용
|
|
66
|
+
- 의도가 명확하면 바로 사용, 불명확하면 제안 후 승인 받기
|
|
67
|
+
|
|
68
|
+
### Code Exploration Strategy
|
|
69
|
+
|
|
70
|
+
#### Parallel Exploration with Multiple Tools
|
|
71
|
+
Combine the following tools in parallel for efficient code exploration:
|
|
72
|
+
|
|
73
|
+
| Tool | Use Case | How to Use |
|
|
74
|
+
|------|----------|------------|
|
|
75
|
+
| **Explorer agent** | Broad codebase exploration, structure understanding | Task tool with `subagent_type=Explore` |
|
|
76
|
+
| **Serena MCP** | Semantic code analysis (symbols, references) | See tools below |
|
|
77
|
+
| **Built-in LSP** | goToDefinition, findReferences, hover | Direct LSP calls |
|
|
78
|
+
|
|
79
|
+
#### Tool Selection Priority
|
|
80
|
+
1. **Serena MCP** - Preferred when available
|
|
81
|
+
2. **Built-in LSP** - Alternative when Serena is unavailable
|
|
82
|
+
3. **Explorer agent** - For broad exploration and structure understanding
|
|
83
|
+
|
|
84
|
+
#### LSP Unavailable Handling
|
|
85
|
+
When Built-in LSP returns "No LSP server available" error:
|
|
86
|
+
1. **STOP** - Halt the current approach
|
|
87
|
+
2. **AskUserQuestion** - Inform user with options:
|
|
88
|
+
- Check if Serena MCP can be activated
|
|
89
|
+
- Or guide LSP server setup for the target language
|
|
90
|
+
|
|
91
|
+
#### Serena MCP Tools
|
|
75
92
|
|
|
76
93
|
| Tool | Use Case |
|
|
77
94
|
|------|----------|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
© 2025 Anthropic, PBC. All rights reserved.
|
|
2
|
+
|
|
3
|
+
LICENSE: Use of these materials (including all code, prompts, assets, files,
|
|
4
|
+
and other components of this Skill) is governed by your agreement with
|
|
5
|
+
Anthropic regarding use of Anthropic's services. If no separate agreement
|
|
6
|
+
exists, use is governed by Anthropic's Consumer Terms of Service or
|
|
7
|
+
Commercial Terms of Service, as applicable:
|
|
8
|
+
https://www.anthropic.com/legal/consumer-terms
|
|
9
|
+
https://www.anthropic.com/legal/commercial-terms
|
|
10
|
+
Your applicable agreement is referred to as the "Agreement." "Services" are
|
|
11
|
+
as defined in the Agreement.
|
|
12
|
+
|
|
13
|
+
ADDITIONAL RESTRICTIONS: Notwithstanding anything in the Agreement to the
|
|
14
|
+
contrary, users may not:
|
|
15
|
+
|
|
16
|
+
- Extract these materials from the Services or retain copies of these
|
|
17
|
+
materials outside the Services
|
|
18
|
+
- Reproduce or copy these materials, except for temporary copies created
|
|
19
|
+
automatically during authorized use of the Services
|
|
20
|
+
- Create derivative works based on these materials
|
|
21
|
+
- Distribute, sublicense, or transfer these materials to any third party
|
|
22
|
+
- Make, offer to sell, sell, or import any inventions embodied in these
|
|
23
|
+
materials
|
|
24
|
+
- Reverse engineer, decompile, or disassemble these materials
|
|
25
|
+
|
|
26
|
+
The receipt, viewing, or possession of these materials does not convey or
|
|
27
|
+
imply any license or right beyond those expressly granted above.
|
|
28
|
+
|
|
29
|
+
Anthropic retains all right, title, and interest in these materials,
|
|
30
|
+
including all copyrights, patents, and other intellectual property rights.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: xlsx
|
|
3
|
+
description: "Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas"
|
|
4
|
+
license: Proprietary. LICENSE.txt has complete terms
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Requirements for Outputs
|
|
8
|
+
|
|
9
|
+
## All Excel files
|
|
10
|
+
|
|
11
|
+
### Zero Formula Errors
|
|
12
|
+
- Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)
|
|
13
|
+
|
|
14
|
+
### Preserve Existing Templates (when updating templates)
|
|
15
|
+
- Study and EXACTLY match existing format, style, and conventions when modifying files
|
|
16
|
+
- Never impose standardized formatting on files with established patterns
|
|
17
|
+
- Existing template conventions ALWAYS override these guidelines
|
|
18
|
+
|
|
19
|
+
## Financial models
|
|
20
|
+
|
|
21
|
+
### Color Coding Standards
|
|
22
|
+
Unless otherwise stated by the user or existing template
|
|
23
|
+
|
|
24
|
+
#### Industry-Standard Color Conventions
|
|
25
|
+
- **Blue text (RGB: 0,0,255)**: Hardcoded inputs, and numbers users will change for scenarios
|
|
26
|
+
- **Black text (RGB: 0,0,0)**: ALL formulas and calculations
|
|
27
|
+
- **Green text (RGB: 0,128,0)**: Links pulling from other worksheets within same workbook
|
|
28
|
+
- **Red text (RGB: 255,0,0)**: External links to other files
|
|
29
|
+
- **Yellow background (RGB: 255,255,0)**: Key assumptions needing attention or cells that need to be updated
|
|
30
|
+
|
|
31
|
+
### Number Formatting Standards
|
|
32
|
+
|
|
33
|
+
#### Required Format Rules
|
|
34
|
+
- **Years**: Format as text strings (e.g., "2024" not "2,024")
|
|
35
|
+
- **Currency**: Use $#,##0 format; ALWAYS specify units in headers ("Revenue ($mm)")
|
|
36
|
+
- **Zeros**: Use number formatting to make all zeros "-", including percentages (e.g., "$#,##0;($#,##0);-")
|
|
37
|
+
- **Percentages**: Default to 0.0% format (one decimal)
|
|
38
|
+
- **Multiples**: Format as 0.0x for valuation multiples (EV/EBITDA, P/E)
|
|
39
|
+
- **Negative numbers**: Use parentheses (123) not minus -123
|
|
40
|
+
|
|
41
|
+
### Formula Construction Rules
|
|
42
|
+
|
|
43
|
+
#### Assumptions Placement
|
|
44
|
+
- Place ALL assumptions (growth rates, margins, multiples, etc.) in separate assumption cells
|
|
45
|
+
- Use cell references instead of hardcoded values in formulas
|
|
46
|
+
- Example: Use =B5*(1+$B$6) instead of =B5*1.05
|
|
47
|
+
|
|
48
|
+
#### Formula Error Prevention
|
|
49
|
+
- Verify all cell references are correct
|
|
50
|
+
- Check for off-by-one errors in ranges
|
|
51
|
+
- Ensure consistent formulas across all projection periods
|
|
52
|
+
- Test with edge cases (zero values, negative numbers)
|
|
53
|
+
- Verify no unintended circular references
|
|
54
|
+
|
|
55
|
+
#### Documentation Requirements for Hardcodes
|
|
56
|
+
- Comment or in cells beside (if end of table). Format: "Source: [System/Document], [Date], [Specific Reference], [URL if applicable]"
|
|
57
|
+
- Examples:
|
|
58
|
+
- "Source: Company 10-K, FY2024, Page 45, Revenue Note, [SEC EDGAR URL]"
|
|
59
|
+
- "Source: Company 10-Q, Q2 2025, Exhibit 99.1, [SEC EDGAR URL]"
|
|
60
|
+
- "Source: Bloomberg Terminal, 8/15/2025, AAPL US Equity"
|
|
61
|
+
- "Source: FactSet, 8/20/2025, Consensus Estimates Screen"
|
|
62
|
+
|
|
63
|
+
# XLSX creation, editing, and analysis
|
|
64
|
+
|
|
65
|
+
## Overview
|
|
66
|
+
|
|
67
|
+
A user may ask you to create, edit, or analyze the contents of an .xlsx file. You have different tools and workflows available for different tasks.
|
|
68
|
+
|
|
69
|
+
## Important Requirements
|
|
70
|
+
|
|
71
|
+
**LibreOffice Required for Formula Recalculation**: You can assume LibreOffice is installed for recalculating formula values using the `recalc.py` script. The script automatically configures LibreOffice on first run
|
|
72
|
+
|
|
73
|
+
## Reading and analyzing data
|
|
74
|
+
|
|
75
|
+
### Data analysis with pandas
|
|
76
|
+
For data analysis, visualization, and basic operations, use **pandas** which provides powerful data manipulation capabilities:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import pandas as pd
|
|
80
|
+
|
|
81
|
+
# Read Excel
|
|
82
|
+
df = pd.read_excel('file.xlsx') # Default: first sheet
|
|
83
|
+
all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # All sheets as dict
|
|
84
|
+
|
|
85
|
+
# Analyze
|
|
86
|
+
df.head() # Preview data
|
|
87
|
+
df.info() # Column info
|
|
88
|
+
df.describe() # Statistics
|
|
89
|
+
|
|
90
|
+
# Write Excel
|
|
91
|
+
df.to_excel('output.xlsx', index=False)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Excel File Workflows
|
|
95
|
+
|
|
96
|
+
## CRITICAL: Use Formulas, Not Hardcoded Values
|
|
97
|
+
|
|
98
|
+
**Always use Excel formulas instead of calculating values in Python and hardcoding them.** This ensures the spreadsheet remains dynamic and updateable.
|
|
99
|
+
|
|
100
|
+
### ❌ WRONG - Hardcoding Calculated Values
|
|
101
|
+
```python
|
|
102
|
+
# Bad: Calculating in Python and hardcoding result
|
|
103
|
+
total = df['Sales'].sum()
|
|
104
|
+
sheet['B10'] = total # Hardcodes 5000
|
|
105
|
+
|
|
106
|
+
# Bad: Computing growth rate in Python
|
|
107
|
+
growth = (df.iloc[-1]['Revenue'] - df.iloc[0]['Revenue']) / df.iloc[0]['Revenue']
|
|
108
|
+
sheet['C5'] = growth # Hardcodes 0.15
|
|
109
|
+
|
|
110
|
+
# Bad: Python calculation for average
|
|
111
|
+
avg = sum(values) / len(values)
|
|
112
|
+
sheet['D20'] = avg # Hardcodes 42.5
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### ✅ CORRECT - Using Excel Formulas
|
|
116
|
+
```python
|
|
117
|
+
# Good: Let Excel calculate the sum
|
|
118
|
+
sheet['B10'] = '=SUM(B2:B9)'
|
|
119
|
+
|
|
120
|
+
# Good: Growth rate as Excel formula
|
|
121
|
+
sheet['C5'] = '=(C4-C2)/C2'
|
|
122
|
+
|
|
123
|
+
# Good: Average using Excel function
|
|
124
|
+
sheet['D20'] = '=AVERAGE(D2:D19)'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
This applies to ALL calculations - totals, percentages, ratios, differences, etc. The spreadsheet should be able to recalculate when source data changes.
|
|
128
|
+
|
|
129
|
+
## Common Workflow
|
|
130
|
+
1. **Choose tool**: pandas for data, openpyxl for formulas/formatting
|
|
131
|
+
2. **Create/Load**: Create new workbook or load existing file
|
|
132
|
+
3. **Modify**: Add/edit data, formulas, and formatting
|
|
133
|
+
4. **Save**: Write to file
|
|
134
|
+
5. **Recalculate formulas (MANDATORY IF USING FORMULAS)**: Use the recalc.py script
|
|
135
|
+
```bash
|
|
136
|
+
python recalc.py output.xlsx
|
|
137
|
+
```
|
|
138
|
+
6. **Verify and fix any errors**:
|
|
139
|
+
- The script returns JSON with error details
|
|
140
|
+
- If `status` is `errors_found`, check `error_summary` for specific error types and locations
|
|
141
|
+
- Fix the identified errors and recalculate again
|
|
142
|
+
- Common errors to fix:
|
|
143
|
+
- `#REF!`: Invalid cell references
|
|
144
|
+
- `#DIV/0!`: Division by zero
|
|
145
|
+
- `#VALUE!`: Wrong data type in formula
|
|
146
|
+
- `#NAME?`: Unrecognized formula name
|
|
147
|
+
|
|
148
|
+
### Creating new Excel files
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
# Using openpyxl for formulas and formatting
|
|
152
|
+
from openpyxl import Workbook
|
|
153
|
+
from openpyxl.styles import Font, PatternFill, Alignment
|
|
154
|
+
|
|
155
|
+
wb = Workbook()
|
|
156
|
+
sheet = wb.active
|
|
157
|
+
|
|
158
|
+
# Add data
|
|
159
|
+
sheet['A1'] = 'Hello'
|
|
160
|
+
sheet['B1'] = 'World'
|
|
161
|
+
sheet.append(['Row', 'of', 'data'])
|
|
162
|
+
|
|
163
|
+
# Add formula
|
|
164
|
+
sheet['B2'] = '=SUM(A1:A10)'
|
|
165
|
+
|
|
166
|
+
# Formatting
|
|
167
|
+
sheet['A1'].font = Font(bold=True, color='FF0000')
|
|
168
|
+
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
|
|
169
|
+
sheet['A1'].alignment = Alignment(horizontal='center')
|
|
170
|
+
|
|
171
|
+
# Column width
|
|
172
|
+
sheet.column_dimensions['A'].width = 20
|
|
173
|
+
|
|
174
|
+
wb.save('output.xlsx')
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Editing existing Excel files
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# Using openpyxl to preserve formulas and formatting
|
|
181
|
+
from openpyxl import load_workbook
|
|
182
|
+
|
|
183
|
+
# Load existing file
|
|
184
|
+
wb = load_workbook('existing.xlsx')
|
|
185
|
+
sheet = wb.active # or wb['SheetName'] for specific sheet
|
|
186
|
+
|
|
187
|
+
# Working with multiple sheets
|
|
188
|
+
for sheet_name in wb.sheetnames:
|
|
189
|
+
sheet = wb[sheet_name]
|
|
190
|
+
print(f"Sheet: {sheet_name}")
|
|
191
|
+
|
|
192
|
+
# Modify cells
|
|
193
|
+
sheet['A1'] = 'New Value'
|
|
194
|
+
sheet.insert_rows(2) # Insert row at position 2
|
|
195
|
+
sheet.delete_cols(3) # Delete column 3
|
|
196
|
+
|
|
197
|
+
# Add new sheet
|
|
198
|
+
new_sheet = wb.create_sheet('NewSheet')
|
|
199
|
+
new_sheet['A1'] = 'Data'
|
|
200
|
+
|
|
201
|
+
wb.save('modified.xlsx')
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Recalculating formulas
|
|
205
|
+
|
|
206
|
+
Excel files created or modified by openpyxl contain formulas as strings but not calculated values. Use the provided `recalc.py` script to recalculate formulas:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
python recalc.py <excel_file> [timeout_seconds]
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Example:
|
|
213
|
+
```bash
|
|
214
|
+
python recalc.py output.xlsx 30
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The script:
|
|
218
|
+
- Automatically sets up LibreOffice macro on first run
|
|
219
|
+
- Recalculates all formulas in all sheets
|
|
220
|
+
- Scans ALL cells for Excel errors (#REF!, #DIV/0!, etc.)
|
|
221
|
+
- Returns JSON with detailed error locations and counts
|
|
222
|
+
- Works on both Linux and macOS
|
|
223
|
+
|
|
224
|
+
## Formula Verification Checklist
|
|
225
|
+
|
|
226
|
+
Quick checks to ensure formulas work correctly:
|
|
227
|
+
|
|
228
|
+
### Essential Verification
|
|
229
|
+
- [ ] **Test 2-3 sample references**: Verify they pull correct values before building full model
|
|
230
|
+
- [ ] **Column mapping**: Confirm Excel columns match (e.g., column 64 = BL, not BK)
|
|
231
|
+
- [ ] **Row offset**: Remember Excel rows are 1-indexed (DataFrame row 5 = Excel row 6)
|
|
232
|
+
|
|
233
|
+
### Common Pitfalls
|
|
234
|
+
- [ ] **NaN handling**: Check for null values with `pd.notna()`
|
|
235
|
+
- [ ] **Far-right columns**: FY data often in columns 50+
|
|
236
|
+
- [ ] **Multiple matches**: Search all occurrences, not just first
|
|
237
|
+
- [ ] **Division by zero**: Check denominators before using `/` in formulas (#DIV/0!)
|
|
238
|
+
- [ ] **Wrong references**: Verify all cell references point to intended cells (#REF!)
|
|
239
|
+
- [ ] **Cross-sheet references**: Use correct format (Sheet1!A1) for linking sheets
|
|
240
|
+
|
|
241
|
+
### Text Content Interpreted as Formulas
|
|
242
|
+
Excel interprets certain text patterns as formulas, causing edit errors in MS Office:
|
|
243
|
+
|
|
244
|
+
| Pattern | Problem | Fix |
|
|
245
|
+
|---------|---------|-----|
|
|
246
|
+
| `=` start | `"====="`, `"==>"` treated as formula | Use `"-----"`, `">>"` instead |
|
|
247
|
+
| `-` start | Bullet points like `"- item"` | Add leading space: `" - item"` |
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
# Fix "-" starting cells
|
|
251
|
+
if cell.value and cell.value.startswith('-'):
|
|
252
|
+
cell.value = ' ' + cell.value
|
|
253
|
+
|
|
254
|
+
# Fix newline + "-" patterns
|
|
255
|
+
if '\n-' in cell.value:
|
|
256
|
+
cell.value = cell.value.replace('\n-', '\n -')
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Formula Testing Strategy
|
|
260
|
+
- [ ] **Start small**: Test formulas on 2-3 cells before applying broadly
|
|
261
|
+
- [ ] **Verify dependencies**: Check all cells referenced in formulas exist
|
|
262
|
+
- [ ] **Test edge cases**: Include zero, negative, and very large values
|
|
263
|
+
|
|
264
|
+
### Interpreting recalc.py Output
|
|
265
|
+
The script returns JSON with error details:
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"status": "success", // or "errors_found"
|
|
269
|
+
"total_errors": 0, // Total error count
|
|
270
|
+
"total_formulas": 42, // Number of formulas in file
|
|
271
|
+
"error_summary": { // Only present if errors found
|
|
272
|
+
"#REF!": {
|
|
273
|
+
"count": 2,
|
|
274
|
+
"locations": ["Sheet1!B5", "Sheet1!C10"]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Best Practices
|
|
281
|
+
|
|
282
|
+
### Library Selection
|
|
283
|
+
- **pandas**: Best for data analysis, bulk operations, and simple data export
|
|
284
|
+
- **openpyxl**: Best for complex formatting, formulas, and Excel-specific features
|
|
285
|
+
|
|
286
|
+
### Working with openpyxl
|
|
287
|
+
- Cell indices are 1-based (row=1, column=1 refers to cell A1)
|
|
288
|
+
- Use `data_only=True` to read calculated values: `load_workbook('file.xlsx', data_only=True)`
|
|
289
|
+
- **Warning**: If opened with `data_only=True` and saved, formulas are replaced with values and permanently lost
|
|
290
|
+
- For large files: Use `read_only=True` for reading or `write_only=True` for writing
|
|
291
|
+
- Formulas are preserved but not evaluated - use recalc.py to update values
|
|
292
|
+
|
|
293
|
+
### Working with pandas
|
|
294
|
+
- Specify data types to avoid inference issues: `pd.read_excel('file.xlsx', dtype={'id': str})`
|
|
295
|
+
- For large files, read specific columns: `pd.read_excel('file.xlsx', usecols=['A', 'C', 'E'])`
|
|
296
|
+
- Handle dates properly: `pd.read_excel('file.xlsx', parse_dates=['date_column'])`
|
|
297
|
+
|
|
298
|
+
## Code Style Guidelines
|
|
299
|
+
**IMPORTANT**: When generating Python code for Excel operations:
|
|
300
|
+
- Write minimal, concise Python code without unnecessary comments
|
|
301
|
+
- Avoid verbose variable names and redundant operations
|
|
302
|
+
- Avoid unnecessary print statements
|
|
303
|
+
|
|
304
|
+
**For Excel files themselves**:
|
|
305
|
+
- Add comments to cells with complex formulas or important assumptions
|
|
306
|
+
- Document data sources for hardcoded values
|
|
307
|
+
- Include notes for key calculations and model sections
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Excel Formula Recalculation Script
|
|
4
|
+
Recalculates all formulas in an Excel file using LibreOffice
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
import subprocess
|
|
10
|
+
import os
|
|
11
|
+
import platform
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from openpyxl import load_workbook
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def setup_libreoffice_macro():
|
|
17
|
+
"""Setup LibreOffice macro for recalculation if not already configured"""
|
|
18
|
+
if platform.system() == 'Darwin':
|
|
19
|
+
macro_dir = os.path.expanduser('~/Library/Application Support/LibreOffice/4/user/basic/Standard')
|
|
20
|
+
else:
|
|
21
|
+
macro_dir = os.path.expanduser('~/.config/libreoffice/4/user/basic/Standard')
|
|
22
|
+
|
|
23
|
+
macro_file = os.path.join(macro_dir, 'Module1.xba')
|
|
24
|
+
|
|
25
|
+
if os.path.exists(macro_file):
|
|
26
|
+
with open(macro_file, 'r') as f:
|
|
27
|
+
if 'RecalculateAndSave' in f.read():
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
if not os.path.exists(macro_dir):
|
|
31
|
+
subprocess.run(['soffice', '--headless', '--terminate_after_init'],
|
|
32
|
+
capture_output=True, timeout=10)
|
|
33
|
+
os.makedirs(macro_dir, exist_ok=True)
|
|
34
|
+
|
|
35
|
+
macro_content = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
36
|
+
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
37
|
+
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">
|
|
38
|
+
Sub RecalculateAndSave()
|
|
39
|
+
ThisComponent.calculateAll()
|
|
40
|
+
ThisComponent.store()
|
|
41
|
+
ThisComponent.close(True)
|
|
42
|
+
End Sub
|
|
43
|
+
</script:module>'''
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
with open(macro_file, 'w') as f:
|
|
47
|
+
f.write(macro_content)
|
|
48
|
+
return True
|
|
49
|
+
except Exception:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def recalc(filename, timeout=30):
|
|
54
|
+
"""
|
|
55
|
+
Recalculate formulas in Excel file and report any errors
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
filename: Path to Excel file
|
|
59
|
+
timeout: Maximum time to wait for recalculation (seconds)
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
dict with error locations and counts
|
|
63
|
+
"""
|
|
64
|
+
if not Path(filename).exists():
|
|
65
|
+
return {'error': f'File {filename} does not exist'}
|
|
66
|
+
|
|
67
|
+
abs_path = str(Path(filename).absolute())
|
|
68
|
+
|
|
69
|
+
if not setup_libreoffice_macro():
|
|
70
|
+
return {'error': 'Failed to setup LibreOffice macro'}
|
|
71
|
+
|
|
72
|
+
cmd = [
|
|
73
|
+
'soffice', '--headless', '--norestore',
|
|
74
|
+
'vnd.sun.star.script:Standard.Module1.RecalculateAndSave?language=Basic&location=application',
|
|
75
|
+
abs_path
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
# Handle timeout command differences between Linux and macOS
|
|
79
|
+
if platform.system() != 'Windows':
|
|
80
|
+
timeout_cmd = 'timeout' if platform.system() == 'Linux' else None
|
|
81
|
+
if platform.system() == 'Darwin':
|
|
82
|
+
# Check if gtimeout is available on macOS
|
|
83
|
+
try:
|
|
84
|
+
subprocess.run(['gtimeout', '--version'], capture_output=True, timeout=1, check=False)
|
|
85
|
+
timeout_cmd = 'gtimeout'
|
|
86
|
+
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
if timeout_cmd:
|
|
90
|
+
cmd = [timeout_cmd, str(timeout)] + cmd
|
|
91
|
+
|
|
92
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
93
|
+
|
|
94
|
+
if result.returncode != 0 and result.returncode != 124: # 124 is timeout exit code
|
|
95
|
+
error_msg = result.stderr or 'Unknown error during recalculation'
|
|
96
|
+
if 'Module1' in error_msg or 'RecalculateAndSave' not in error_msg:
|
|
97
|
+
return {'error': 'LibreOffice macro not configured properly'}
|
|
98
|
+
else:
|
|
99
|
+
return {'error': error_msg}
|
|
100
|
+
|
|
101
|
+
# Check for Excel errors in the recalculated file - scan ALL cells
|
|
102
|
+
try:
|
|
103
|
+
wb = load_workbook(filename, data_only=True)
|
|
104
|
+
|
|
105
|
+
excel_errors = ['#VALUE!', '#DIV/0!', '#REF!', '#NAME?', '#NULL!', '#NUM!', '#N/A']
|
|
106
|
+
error_details = {err: [] for err in excel_errors}
|
|
107
|
+
total_errors = 0
|
|
108
|
+
|
|
109
|
+
for sheet_name in wb.sheetnames:
|
|
110
|
+
ws = wb[sheet_name]
|
|
111
|
+
# Check ALL rows and columns - no limits
|
|
112
|
+
for row in ws.iter_rows():
|
|
113
|
+
for cell in row:
|
|
114
|
+
if cell.value is not None and isinstance(cell.value, str):
|
|
115
|
+
for err in excel_errors:
|
|
116
|
+
if err in cell.value:
|
|
117
|
+
location = f"{sheet_name}!{cell.coordinate}"
|
|
118
|
+
error_details[err].append(location)
|
|
119
|
+
total_errors += 1
|
|
120
|
+
break
|
|
121
|
+
|
|
122
|
+
wb.close()
|
|
123
|
+
|
|
124
|
+
# Build result summary
|
|
125
|
+
result = {
|
|
126
|
+
'status': 'success' if total_errors == 0 else 'errors_found',
|
|
127
|
+
'total_errors': total_errors,
|
|
128
|
+
'error_summary': {}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# Add non-empty error categories
|
|
132
|
+
for err_type, locations in error_details.items():
|
|
133
|
+
if locations:
|
|
134
|
+
result['error_summary'][err_type] = {
|
|
135
|
+
'count': len(locations),
|
|
136
|
+
'locations': locations[:20] # Show up to 20 locations
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
# Add formula count for context - also check ALL cells
|
|
140
|
+
wb_formulas = load_workbook(filename, data_only=False)
|
|
141
|
+
formula_count = 0
|
|
142
|
+
for sheet_name in wb_formulas.sheetnames:
|
|
143
|
+
ws = wb_formulas[sheet_name]
|
|
144
|
+
for row in ws.iter_rows():
|
|
145
|
+
for cell in row:
|
|
146
|
+
if cell.value and isinstance(cell.value, str) and cell.value.startswith('='):
|
|
147
|
+
formula_count += 1
|
|
148
|
+
wb_formulas.close()
|
|
149
|
+
|
|
150
|
+
result['total_formulas'] = formula_count
|
|
151
|
+
|
|
152
|
+
return result
|
|
153
|
+
|
|
154
|
+
except Exception as e:
|
|
155
|
+
return {'error': str(e)}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def main():
|
|
159
|
+
if len(sys.argv) < 2:
|
|
160
|
+
print("Usage: python recalc.py <excel_file> [timeout_seconds]")
|
|
161
|
+
print("\nRecalculates all formulas in an Excel file using LibreOffice")
|
|
162
|
+
print("\nReturns JSON with error details:")
|
|
163
|
+
print(" - status: 'success' or 'errors_found'")
|
|
164
|
+
print(" - total_errors: Total number of Excel errors found")
|
|
165
|
+
print(" - total_formulas: Number of formulas in the file")
|
|
166
|
+
print(" - error_summary: Breakdown by error type with locations")
|
|
167
|
+
print(" - #VALUE!, #DIV/0!, #REF!, #NAME?, #NULL!, #NUM!, #N/A")
|
|
168
|
+
sys.exit(1)
|
|
169
|
+
|
|
170
|
+
filename = sys.argv[1]
|
|
171
|
+
timeout = int(sys.argv[2]) if len(sys.argv) > 2 else 30
|
|
172
|
+
|
|
173
|
+
result = recalc(filename, timeout)
|
|
174
|
+
print(json.dumps(result, indent=2))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if __name__ == '__main__':
|
|
178
|
+
main()
|