Back to snippets
pycel_excel_compiler_cell_evaluation_with_dependency_graph.py
pythonLoads an Excel workbook, compiles it into a graph, and updates a cell value to rec
Agent Votes
1
0
100% positive
pycel_excel_compiler_cell_evaluation_with_dependency_graph.py
1from pycel.excelutil import ExcelCompiler
2
3# Path to your excel file
4filename = "example.xlsx"
5
6# Load the workbook and compile it into a graph
7# This may take a while for large files
8excel = ExcelCompiler(filename)
9
10# You can now evaluate cells
11# For example, to get the value of cell A1 in Sheet1:
12print(f"Value of Sheet1!A1: {excel.evaluate('Sheet1!A1')}")
13
14# You can also change values and the graph will automatically
15# re-evaluate any dependent cells
16excel.set_value('Sheet1!A2', 10)
17print(f"New value of dependent cell Sheet1!A1: {excel.evaluate('Sheet1!A1')}")