Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ExpressionContext.ExpressionStyle Property

Gets or sets the worksheet-specific parameter which determines how the formula is interpreted and calculated.

Namespace: DevExpress.Spreadsheet.Formulas

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

Declaration

public ExpressionStyle ExpressionStyle { get; set; }

Property Value

Type Description
ExpressionStyle

An ExpressionStyle enumeration member specifying how the formula is interpreted.

Remarks

The ExpressionStyle property allows you to calculate the formula as if it is an array formula in the worksheet, or obtain a series of data values rather than a single value. Consider the formula “=ROW(A1:A10)” - it returns the value 1 if the ExpressionStyle is ExpressionStyle.Normal, and the array of numbers from 1 to 10 if the ExpressionStyle is ExpressionStyle.Array. The formula “=ABS({-2,0,3})” returns 2 if the ExpressionStyle is ExpressionStyle.Normal and the array {2,0,3} if the ExpressionStyle is ExpressionStyle.DefinedName.

Example

Imports DevExpress.Spreadsheet
Imports DevExpress.Spreadsheet.Formulas
Imports DevExpress.Spreadsheet.Functions
            Dim engine As FormulaEngine = spreadsheetControl1.Document.FormulaEngine
            ' Get coordinates of the active cell.
            Dim columnIndex As Integer = spreadsheetControl1.ActiveCell.ColumnIndex
            Dim rowIndex As Integer = spreadsheetControl1.ActiveCell.RowIndex
            ' Create the expression context.
            Dim context As New ExpressionContext(columnIndex, rowIndex, Me.contextSheet, CultureInfo.GetCultureInfo("en-US"), ReferenceStyle.UseDocumentSettings, DirectCast(editExpressionStyle.EditValue, ExpressionStyle))
            ' Evaluate the expression.
            Dim result As ParameterValue = engine.Evaluate(spreadsheetControl1.ActiveCell.Formula, context)
            ' Get the result.
            Dim res As String = String.Empty

            If result.IsArray Then
                res &= Environment.NewLine
                Dim rowLength As Integer = result.ArrayValue.GetLength(0)
                Dim colLength As Integer = result.ArrayValue.GetLength(1)

                For i As Integer = 0 To rowLength - 1
                    For j As Integer = 0 To colLength - 1
                        res &= String.Format("{0} ", result.ArrayValue(i, j))
                    Next j
                    res &= Environment.NewLine
                Next i
            Else
                res = result.ToString()
            End If

Implements

See Also