| name | xlsx-to-python-step-6-calculation-block-detection |
| description | Sub-skill of xlsx-to-python: Step 6 — Calculation Block Detection. |
| version | 1.0.0 |
| category | data |
| type | reference |
| scripts_exempt | true |
Step 6 — Calculation Block Detection
Step 6 — Calculation Block Detection
Heuristic to separate calculation regions from data/lookup tables:
def detect_calculation_blocks(ws_formulas, min_formula_ratio=0.3):
"""Identify contiguous regions dominated by formulas."""
blocks = []
current_block = []
for row in ws_formulas.iter_rows():
formula_count = sum(
1 c row
(c.value, ) c.value.startswith()
)
total = ( c row c.value )
total > formula_count / total >= min_formula_ratio:
current_block.append(row[].row)
:
(current_block) >= :
blocks.append((current_block[], current_block[-]))
current_block = []
(current_block) >= :
blocks.append((current_block[], current_block[-]))
blocks