Skip to main content

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.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public ExpressionStyle ExpressionStyle { get; set; }

Property Value

Type Description
ExpressionStyle

An ExpressionStyle enumeration member specifying how the formula is interpreted.

Available values:

Name Description
Normal

Formula is calculated as if it is entered in the worksheet cell in the usual way. It does not operate with arrays to return arrays.

Array

Formula is calculated as an array formula in a worksheet.

DefinedName

The formula works with an array of values.

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

View 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