Skip to content

Commit f45b63e

Browse files
committed
Documentation
1 parent 0b49304 commit f45b63e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Single-cell references in a formula sitting in cell `A3` like `=A1+A2` is consid
1919

2020
A range defined in a formula like `=SUM(B1:B200)` is semantically handled like a single reference or node in the tree and not 200 individual nodes in the graph.
2121

22+
The way the graph is built is by iterating over all cells in the spreadsheet and extracting the references in the formula of each cell. The references are then added as edges in the graph.
23+
24+
A cell within a range is considered a dependency of the range itself, but not of the other cells in the range.
25+
2226
## Installation
2327

2428
```bash

graphbuilder.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ def extract_formulas_and_build_dependencies(file_path):
5959
ws = wb[sheet_name]
6060
log(f"-- Analyzing sheet: {sheet_name} --")
6161

62-
# Iterate over all cells
62+
# Iterate over all cells in the sheet and extract formulas
6363
for row in ws.iter_rows():
6464
for cell in row:
65+
# only interested in cells with formulas
6566
if isinstance(cell.value, str) and cell.value.startswith("="):
67+
# collect functions usage statistics
6668
stat_functions(cell.value)
6769

6870
cell_name = f"{sheet_name}!{cell.coordinate}"
@@ -75,7 +77,8 @@ def extract_formulas_and_build_dependencies(file_path):
7577
cell.value
7678
)
7779

78-
# Add the cell and its dependencies to the graph
80+
# all the referenced cells and cells from expanded ranges
81+
# is added to the graph as nodes and edges
7982
for ref_cell in referenced_cells:
8083
if "!" not in ref_cell:
8184
# No sheet specified, assume current sheet
@@ -84,10 +87,14 @@ def extract_formulas_and_build_dependencies(file_path):
8487
refc = ref_cell
8588

8689
log(f" Depends on: {refc}")
90+
# add the node
8791
graph.add_node(refc, sheet=sheet_name)
92+
# add the edge
8893
graph.add_edge(cell_name, refc)
8994

90-
# Add dependencies for ranges
95+
# If a range like A1:B3 is referenced, add the
96+
# edge between the cells within that range and
97+
# the range istself
9198
for single_cell, range_ref in range_dependencies.items():
9299
if "!" not in range_ref:
93100
range_ref = f"{sheet_name}!{range_ref}"

0 commit comments

Comments
 (0)