Spread for ASP.NET 9.0 Product Documentation > Developer's Guide > Customizing User Interaction > Customizing Interaction with Cells > Using Conditional Formatting in Cells > Conditional Formatting of Cells |
You can set up conditional formats within cells that determine the formatting of the cell based on the outcome of a conditional statement. You can use a named style to specify various formatting options such as borders and colors to apply if the condition statement is valid, that is, if the operation is satisfied.
For example, you may want to change the background color of a cell based on the value of the cell. If the value is below 100 then the background color would be changed to red. The condition statement is "less than 100" and consists of a comparison operator "less than" and a condition, in this case a single constant "100". The condition can be a constant (expressed as a string) or an expression. Some condition statements have two conditions and an operator: for instance, if the cell value is between 0 and 100, then change the background color. In this case, the comparison operator is “between” and the first condition is 0 and the last condition is 100. For a complete list of operations, refer to the ComparisonOperator enumeration. For a list of the types of expressions, refer to the CalcEngine.Expression object. For more information about the possible style settings, refer to Creating and Applying a Custom Style for Cells.
If two conditional formats are set to the same cell, the second conditional format takes effect.
Use the SetConditionalFormat method to create a conditional format.
The following example changes the color of the cell if the value is greater than 14.
C# |
Copy Code
|
---|---|
FarPoint.Web.Spread.NamedStyle ns = new FarPoint.Web.Spread.NamedStyle(); ns.BackColor = Color.Crimson; ns.Name = "mystyle"; FpSpread1.NamedStyles.Add(ns); FpSpread1.Sheets[0].SetConditionalFormat(0, 0, ns, FarPoint.Web.Spread.ComparisonOperator.GreaterThan, "14"); |
VB |
Copy Code
|
---|---|
Dim ns As New FarPoint.Web.Spread.NamedStyle ns.BackColor = Drawing.Color.Azure ns.Name = "mystyle" FpSpread1.NamedStyles.Add(ns) FpSpread1.Sheets(0).SetConditionalFormat(0, 0, ns, FarPoint.Web.Spread.ComparisonOperator.GreaterThan, "14") |