GrapeCity SPREAD for WPF 2.0J
SetFormula メソッド

行インデックス。
列インデックス。
指定したセルに設定する数式。
カルチャ。
参照スタイル。
指定したセルの数式を GcSpreadGrid に設定します。
構文
'Declaration
 
Public Sub SetFormula( _
   ByVal row As Integer, _
   ByVal column As Integer, _
   ByVal formula As String, _
   Optional ByVal culture As CultureInfo, _
   Optional ByVal referenceStyle As Nullable(Of ReferenceStyle) _
) 

パラメータ

row
行インデックス。
column
列インデックス。
formula
指定したセルに設定する数式。
culture
カルチャ。
referenceStyle
参照スタイル。
次のサンプルはSetFormulaメソッドの使用方法を説明します。
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 メンバ

 

 


Copyright © 2012 GrapeCity inc. All rights reserved.