LesterLyu / fast-formula-parser

Parse and evaluate MS Excel formula in javascript.
https://www.npmjs.com/package/fast-formula-parser
MIT License
454 stars 63 forks source link

How to handle formula with dependent arguments containing formula? #61

Closed charanjit-singh closed 8 months ago

charanjit-singh commented 8 months ago

For example how to handle formula SUM(A1,B2) if A1 is also =B4-B3?

michaeltford commented 8 months ago

@charanjit-singh this would result in two calculations.

I am assuming that this is not a cyclical dependency.

The way to solve this is to resolve these in dependency order (a topological sort can do this in a generalized way see https://en.wikipedia.org/wiki/Dependency_graph and https://en.wikipedia.org/wiki/Topological_sorting). By sorting all calced values in a 'shared map' you can then return the calculated value via the onCell method

charanjit-singh commented 8 months ago

Thanks @michaeltford ,

Do you have any example?

michaeltford commented 8 months ago

@charanjit-singh Not at the moment but I am considering building one in the near future.