This example demonstrates how to use the FormulaEngine class to evaluate worksheet formulas and parse expressions.
Select a cell and click the Set Context Cell button to specify a cell used to create the ExpressionContext object. The context cell is highlighted with blue color.
Click Evaluate Predefined Formula to calculate a simple formula SUM(R[-2]C:R[-1]C) by the the FormulaEngine.Evaluate method call with the specified context.
Click Parse and Modify Active Cell Formula to call the FormulaEngine.Parse method and create an expression tree from the active cell formula. Subsequently a custom `Visitor`` object is used to traverse the tree and increment row indexes which define an area referenced in the formula.
The Switch R1C1 button can be used to change worksheet reference style if required to correctly interpret formula references.
To calculate formula contained in the active cell using different ExpressionStyle settings, click Evaluate Cell Formula. When executed for the ROW(R2:R11) formula, the Normal expression style setting returns 1, the first row number, and the Array
expression style returns an array of row numbers.
- Form1.cs (VB: Form1.vb)
- MyVisitor.cs (VB: MyVisitor.vb)
(you will be redirected to DevExpress.com to submit your response)