Spread WPF 14
GrapeCity.Windows.SpreadSheet.Data Namespace / FormulaRule Class / Create Method
The condition formula.
The style that is set by the rule.
Example


In This Topic
    Create Method (FormulaRule)
    In This Topic
    Creates a new formula rule with specified parameters.
    Syntax
    'Declaration
     
    Public Shared Function Create( _
       ByVal formula As String, _
       ByVal style As StyleInfo _
    ) As FormulaRule
    'Usage
     
    Dim formula As String
    Dim style As StyleInfo
    Dim value As FormulaRule
     
    value = FormulaRule.Create(formula, style)
    public static FormulaRule Create( 
       string formula,
       StyleInfo style
    )

    Parameters

    formula
    The condition formula.
    style
    The style that is set by the rule.

    Return Value

    The new formula rule.
    Example
    This example uses the formula rule to compare the cell range in column A to the sum of column B and C.
    var style = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
    style.Background = new SolidColorBrush(Colors.Blue);
    style.BorderLeft = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderTop = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderRight = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    style.BorderBottom = new GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red);
    var style1 = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
    style1.Background = new SolidColorBrush(Colors.Green);
    var style2 = new GrapeCity.Windows.SpreadSheet.Data.StyleInfo();
    style2.Background = new SolidColorBrush(Colors.Yellow);
    
    var rule = GrapeCity.Windows.SpreadSheet.Data.FormulaRule.Create("=A1=B1+C1", style);           
    rule.Ranges = new GrapeCity.Windows.SpreadSheet.Data.CellRange[] { new GrapeCity.Windows.SpreadSheet.Data.CellRange(0, 0, 5, 1) };
    gcSpreadSheet1.Sheets[0].ConditionalFormats.AddRule(rule);
    
    gcSpreadSheet1.Sheets[0].Cells[0, 0].Value = 2;
    gcSpreadSheet1.Sheets[0].Cells[0, 1].Value = 1;
    gcSpreadSheet1.Sheets[0].Cells[0, 2].Value = 1;
    gcSpreadSheet1.Sheets[0].Cells[1, 0].Value = 1;
    gcSpreadSheet1.Invalidate();
    Dim style As New GrapeCity.Windows.SpreadSheet.Data.StyleInfo()
    style.Background = New SolidColorBrush(Colors.Blue)
    style.BorderLeft = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderTop = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderRight = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    style.BorderBottom = New GrapeCity.Windows.SpreadSheet.Data.BorderLine(Colors.Red)
    Dim style1 As New GrapeCity.Windows.SpreadSheet.Data.StyleInfo()
    style1.Background = New SolidColorBrush(Colors.Green)
    Dim style2 As New GrapeCity.Windows.SpreadSheet.Data.StyleInfo()
    style2.Background = New SolidColorBrush(Colors.Yellow)
    
    Dim s As New GrapeCity.Windows.SpreadSheet.Data.StyleInfo()
    Dim rule = GrapeCity.Windows.SpreadSheet.Data.FormulaRule.Create("=A1=B1+C1", style)
    rule.Ranges = New GrapeCity.Windows.SpreadSheet.Data.CellRange() {New GrapeCity.Windows.SpreadSheet.Data.CellRange(0, 0, 5, 1)}
    GcSpreadSheet1.Sheets(0).ConditionalFormats.AddRule(rule)
    
    GcSpreadSheet1.Sheets(0).Cells(0, 0).Value = 2
    GcSpreadSheet1.Sheets(0).Cells(0, 1).Value = 1
    GcSpreadSheet1.Sheets(0).Cells(0, 2).Value = 1
    GcSpreadSheet1.Sheets(0).Cells(1, 0).Value = 1
    GcSpreadSheet1.Invalidate()
    See Also