|
8 | 8 | import networkx as nx
|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 |
|
11 |
| -# Regular expression to detect cell references like A1, B2, or ranges like A1:B2 |
12 |
| - |
13 |
| -# ignore linting error for regex pattern |
14 |
| -CELL_REF_REGEX = r"('?[A-Za-z0-9_\-\[\] ]+'?![A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)|([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)" |
| 11 | +# Regex to detect cell references like A1, B2, or ranges like A1:B2 |
| 12 | +CELL_REF_REGEX = r"('?[A-Za-z0-9_\-\[\] ]+'?![A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)|([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)" # noqa |
15 | 13 |
|
16 | 14 |
|
17 | 15 | def extract_formulas_and_build_dependencies(file_path):
|
@@ -45,7 +43,7 @@ def extract_formulas_and_build_dependencies(file_path):
|
45 | 43 | # Add the cell and its dependencies to the graph
|
46 | 44 | for ref_cell in referenced_cells:
|
47 | 45 | if "!" not in ref_cell:
|
48 |
| - # No sheet specified in the reference, assume current sheet |
| 46 | + # No sheet specified in the assume current sheet |
49 | 47 | refc = f"{sheet_name}!{ref_cell}"
|
50 | 48 | else:
|
51 | 49 | refc = ref_cell
|
@@ -85,13 +83,12 @@ def extract_references(formula):
|
85 | 83 | """
|
86 | 84 | formula = formula.replace("$", "")
|
87 | 85 | matches = re.findall(CELL_REF_REGEX, formula)
|
88 |
| - # extracted_references = [match[0].replace("$", "") for match in matches if match[0]] |
89 |
| - extracted_references = [match[0] if match[0] else match[2] for match in matches] |
| 86 | + references = [match[0] if match[0] else match[2] for match in matches] |
90 | 87 |
|
91 | 88 | # trim the extracted references
|
92 |
| - extracted_references = [ref.strip() for ref in extracted_references] |
| 89 | + references = [ref.strip() for ref in references] |
93 | 90 |
|
94 |
| - return extracted_references |
| 91 | + return references |
95 | 92 |
|
96 | 93 |
|
97 | 94 | def visualize_dependency_graph(graph, file_path):
|
|
0 commit comments