dgorissen / pycel

A library for compiling excel spreadsheets to python code & visualizing them as a graph
GNU General Public License v3.0
573 stars 152 forks source link

Is there a way to get the list of dependent cells? #70

Closed tactycHQ closed 5 years ago

tactycHQ commented 5 years ago

I am trying to see if there is an easy way to get a list of all dependencies for a particular cell. I understand I could view the graph, but I'd like to get the dependencies in a linear form (list, dictionary, tuple etc.) for further analysis.

Which function can I call in the ExcelCompiler class to obtain this for a particular cell?

I tried using the cell_map function but I don't believe it lays out ALL the dependencies for a given cell. From what I can tell, its simply displaying the formula in a given cell.

I see there is a needed_addresses function in the _Cell class, however I am not clear how to access that function from the ExcelCompiler instance.

Any help would be appreciated!

stephenrauch commented 5 years ago

The cell_map is a dict of addresses to the formula/value in the cell. The cell_map is generated on demand. Thus, if you evaluate only the single cell you are interested in, any address (keys) in the cell_map will be there because it was in the dependency tree for the evaluated cell.

needed_addresses is just the needed_addresses for that single cell.