The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

FormulaEngine.Evaluate(String, ExpressionContext) Method

Evaluates the specified formula using the specified context.

Namespace: DevExpress.Spreadsheet.Formulas

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

ParameterValue Evaluate(
    string formula,
    ExpressionContext context
)
Function Evaluate(
    formula As String,
    context As ExpressionContext
) As ParameterValue
ParameterValue Evaluate(
    string formula,
    ExpressionContext context
)
Function Evaluate(
    formula As String,
    context As ExpressionContext
) As ParameterValue
ParameterValue Evaluate(
    string formula,
    ExpressionContext context
)
Function Evaluate(
    formula As String,
    context As ExpressionContext
) As ParameterValue

Parameters

Name Type Description
formula String

A string that is the formula to evaluate. Note that the leading equal sign "=" in the formula is optional and can be omitted.

context ExpressionContext

An ExpressionContext object providing information on the cell for which a formula will be evaluated.

Parameters

Name Type Description
formula String

A string that is the formula to evaluate. Note that the leading equal sign "=" in the formula is optional and can be omitted.

context ExpressionContext

An ExpressionContext object providing information on the cell for which a formula will be evaluated.

Parameters

Name Type Description
formula String

A string that is the formula to evaluate. Note that the leading equal sign "=" in the formula is optional and can be omitted.

context ExpressionContext

An ExpressionContext object providing information on the cell for which a formula will be evaluated.

Returns

Type Description
ParameterValue

A ParameterValue object containing the result of the formula calculation.

Returns

Type Description
ParameterValue

A ParameterValue object containing the result of the formula calculation.

Returns

Type Description
ParameterValue

A ParameterValue object containing the result of the formula calculation.

Remarks

Use the Evaluate method to calculate a worksheet formula for any cell in any worksheet. To do this, create or obtain the expression context that specifies the worksheet environment for which the formula will be evaluated.

This code snippet evaluates the formula "SUM(R[-2]C:R[-1]C)" that sums up two cells above the context cell for which the formula is calculated. The context cell can be any worksheet cell. In this example, it is specified earlier in code.

The ExpressionContext that determines the environment in which the formula is calculated, is created by using the Cell.ColumnIndex and Cell.RowIndex properties of the context cell, the current worksheet, the default "en-US" culture, formula type that is not an Array Formula and the ReferenceStyle.R1C1 cell reference style.

The FormulaEngine.Evaluate method calculates formula for the specified context and returns the object of the ParameterValue type that can be easily transformed to the required standard type in this case, double.

Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Formulas
Imports DevExpress.Spreadsheet.Functions
            Dim engine As FormulaEngine = spreadsheetControl1.Document.FormulaEngine
            ' Get coordinates of the context cell.
            Dim columnIndex As Integer = Me.contextCell.ColumnIndex
            Dim rowIndex As Integer = Me.contextCell.RowIndex
            ' Create the expression context.
            Dim context As New ExpressionContext(columnIndex, rowIndex, Me.contextSheet, CultureInfo.GetCultureInfo("en-US"), ReferenceStyle.R1C1, DevExpress.Spreadsheet.Formulas.ExpressionStyle.Normal)
            ' Evaluate the expression.
            Dim result As ParameterValue = engine.Evaluate("SUM(R[-2]C:R[-1]C)", context)
            ' Get the result.
            Dim res As Double = result.NumericValue
See Also