FormatCondition Class
Represents conditional formatting condition.
Inheritance Hierarchy
SystemObject
  Aspose.CellsFormatCondition

Namespace: Aspose.Cells
Assembly: Aspose.Cells (in Aspose.Cells.dll) Version: 19.11.0.0 (19.11)
Syntax
public class FormatCondition

The FormatCondition type exposes the following members.

Properties
  NameDescription
Public propertyAboveAverage
Get the conditional formatting's "AboveAverage" instance. The default instance's rule highlights cells that are above the average for all values in the range. Valid only for type = AboveAverage.
Public propertyColorScale
Get the conditional formatting's "ColorScale" instance. The default instance is a "green-yellow-red" 3ColorScale . Valid only for type = ColorScale.
Public propertyDataBar
Get the conditional formatting's "DataBar" instance. The default instance's color is blue. Valid only for type is DataBar.
Public propertyFormula1
Gets and sets the value or expression associated with conditional formatting.
Public propertyFormula2
Gets and sets the value or expression associated with conditional formatting.
Public propertyIconSet
Get the conditional formatting's "IconSet" instance. The default instance's IconSetType is TrafficLights31. Valid only for type = IconSet.
Public propertyOperator
Gets and sets the conditional format operator type.
Public propertyPriority
The priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where '1' is the highest priority.
Public propertyStopIfTrue
True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;
Public propertyStyle
Gets or setts style of conditional formatted cell ranges.
Public propertyText
The text value in a "text contains" conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.
Public propertyTimePeriod
The applicable time period in a "date occurring¡­" conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.
Public propertyTop10
Get the conditional formatting's "Top10" instance. The default instance's rule highlights cells whose values fall in the top 10 bracket. Valid only for type is Top10.
Public propertyType
Gets and sets whether the conditional format Type.
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetFormula1(Boolean, Boolean)
Gets the value or expression associated with this format condition.
Public methodGetFormula1(Int32, Int32)
Gets the formula of the conditional formatting of the cell.
Public methodGetFormula1(Boolean, Boolean, Int32, Int32)
Gets the value or expression of the conditional formatting of the cell.
Public methodGetFormula2(Boolean, Boolean)
Gets the value or expression associated with this format condition.
Public methodGetFormula2(Int32, Int32)
Gets the formula of the conditional formatting of the cell.
Public methodGetFormula2(Boolean, Boolean, Int32, Int32)
Gets the value or expression of the conditional formatting of the cell.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSetFormula1
Sets the value or expression associated with this format condition.
Public methodSetFormula2
Sets the value or expression associated with this format condition.
Public methodSetFormulas
Sets the value or expression associated with this format condition.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Examples
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];

//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);

ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);

//Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");

//Adds condition.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");

//Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;

//Saving the Excel file
workbook.Save("C:\\output.xls");

[VB.NET]

'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)

' Adds an empty conditional formatting
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)

'Sets the conditional format range.
Dim ca As CellArea = New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)

'Adds condition.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")

'Adds condition.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")

'Sets the background color.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red

'Saving the Excel file
workbook.Save("C:\output.xls")
See Also