SPREAD for WPF 3.0J - GcSpreadGrid
SetExpression メソッド
使用例 

GrapeCity.Windows.SpreadGrid 名前空間 > GcSpreadGrid クラス : SetExpression メソッド
行インデックス。
列インデックス。
指定したセルに設定する式。
指定したセルの式を GcSpreadGrid に設定します。
シンタックス
'宣言
 
Public Sub SetExpression( _
   ByVal row As Integer, _
   ByVal column As Integer, _
   ByVal expression As GrapeCity.CalcEngine.Expressions.CalcExpression _
) 
public void SetExpression( 
   int row,
   int column,
   GrapeCity.CalcEngine.Expressions.CalcExpression expression
)

パラメータ

row
行インデックス。
column
列インデックス。
expression
指定したセルに設定する式。
使用例
次のサンプルはSetExpressionメソッドの使用方法を説明します。
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
参照

GcSpreadGrid クラス
GcSpreadGrid メンバ