public void Formula4()
{
GcSpreadGrid gcSpread1 = new GcSpreadGrid();
gcSpread1.CanUserEditFormula = true; // Allow the users edit formula by UI (user interface).
gcSpread1.Columns[0].Name = "column1";
gcSpread1[0, 0].Value = 1;
gcSpread1[0, 1].Value = 2;
gcSpread1[1, 0].Value = 3;
gcSpread1[1, 1].Value = 4;
gcSpread1[0, 2].Formula = "SUM(A1:B2)";
gcSpread1[1, 2].Formula = "SUM(column1)"; // You can use the column name on formula.
object result = gcSpread1[0, 2].Value; // The value of result is 10.
result = gcSpread1[1, 2].Value; // The value of result is 4.
string formula = gcSpread1.GetFormula(0, 2); // the value of formula is "SUM(A1:B2)";
gcSpread1.SetFormula(0, 2, "AVERAGE(A1:B2)");
result = gcSpread1[0, 2].Value; // The value of result is 2.5.
CalcExpression expression = gcSpread1.GetExpression(0, 2) as CalcExpression;
expression = new CalcBinaryOperatorExpression(CalcBinaryOperators.Add, expression, new CalcDoubleExpression(10));
gcSpread1.SetExpression(0, 2, expression);
result = gcSpread1[0, 2].Value;// The value of result is 12.5.
formula = gcSpread1.GetFormula(0, 2);// the value of formula is "AVERAGE(A1:A2)+10";
}
Public Sub Formula4()
Dim gcSpread1 As New GcSpreadGrid()
gcSpread1.CanUserEditFormula = True
' Allow the users edit formula by UI (user interface).
gcSpread1.Columns(0).Name = "column1"
gcSpread1(0, 0).Value = 1
gcSpread1(0, 1).Value = 2
gcSpread1(1, 0).Value = 3
gcSpread1(1, 1).Value = 4
gcSpread1(0, 2).Formula = "SUM(A1:B2)"
gcSpread1(1, 2).Formula = "SUM(column1)"
' You can use the column name on formula.
Dim result As Object = gcSpread1(0, 2).Value
' The value of result is 10.
result = gcSpread1(1, 2).Value
' The value of result is 4.
Dim formula As String = gcSpread1.GetFormula(0, 2)
' the value of formula is "SUM(A1:B2)";
gcSpread1.SetFormula(0, 2, "AVERAGE(A1:B2)")
result = gcSpread1(0, 2).Value
' The value of result is 2.5.
Dim expression As CalcExpression = TryCast(gcSpread1.GetExpression(0, 2), CalcExpression)
expression = New CalcBinaryOperatorExpression(CalcBinaryOperators.Add, expression, New CalcDoubleExpression(10))
gcSpread1.SetExpression(0, 2, expression)
result = gcSpread1(0, 2).Value
' The value of result is 12.5.
formula = gcSpread1.GetFormula(0, 2)
' the value of formula is "AVERAGE(A1:A2)+10";
End Sub