Exemplo n.º 1
0
 private void btnEvaluate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     #region #evaluate
     FormulaEngine engine = spreadsheetControl1.Document.FormulaEngine;
     // Get coordinates of the context cell.
     int columnIndex = this.contextCell.ColumnIndex;
     int rowIndex    = this.contextCell.RowIndex;
     // Create the expression context.
     ExpressionContext context = new ExpressionContext(columnIndex, rowIndex, this.contextSheet,
                                                       CultureInfo.GetCultureInfo("en-US"), ReferenceStyle.R1C1, DevExpress.Spreadsheet.Formulas.ExpressionStyle.Normal);
     // Evaluate the expression.
     ParameterValue result = engine.Evaluate("SUM(R[-2]C:R[-1]C)", context);
     // Get the result.
     double res = result.NumericValue;
     #endregion #evaluate
     MessageBox.Show(String.Format("The result is {0}", res), "Evaluate Test");
 }
Exemplo n.º 2
0
        private void btnEvaluateExpressionStyle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            #region #evaluateExpressionStyle
            FormulaEngine engine = spreadsheetControl1.Document.FormulaEngine;
            // Get coordinates of the active cell.
            int columnIndex = spreadsheetControl1.ActiveCell.ColumnIndex;
            int rowIndex    = spreadsheetControl1.ActiveCell.RowIndex;
            // Create the expression context.
            ExpressionContext context = new ExpressionContext(columnIndex, rowIndex, this.contextSheet,
                                                              CultureInfo.GetCultureInfo("en-US"), ReferenceStyle.UseDocumentSettings, (ExpressionStyle)editExpressionStyle.EditValue);
            // Evaluate the expression.
            ParameterValue result = engine.Evaluate(spreadsheetControl1.ActiveCell.Formula, context);
            // Get the result.
            string res = string.Empty;

            if (result.IsArray)
            {
                res += Environment.NewLine;
                int rowLength = result.ArrayValue.GetLength(0);
                int colLength = result.ArrayValue.GetLength(1);

                for (int i = 0; i < rowLength; i++)
                {
                    for (int j = 0; j < colLength; j++)
                    {
                        res += String.Format("{0} ", result.ArrayValue[i, j]);
                    }
                    res += Environment.NewLine;
                }
            }
            else
            {
                res = result.ToString();
            }
            #endregion #evaluateExpressionStyle
            MessageBox.Show(String.Format("The result is {0}", res), "Evaluate Using Expression Style");
        }