FormatConditionCollection Class

Represents conditional formatting. The FormatConditions can contain up to three conditional formats.
Inheritance Hierarchy
SystemObject
  Aspose.CellsFormatConditionCollection

Namespace:  Aspose.Cells
Assembly:  Aspose.Cells (in Aspose.Cells.dll) Version: 20.1.0.0 (20.1)
Syntax
public class FormatConditionCollection

The FormatConditionCollection type exposes the following members.

Properties
  NameDescription
Public propertyCount
Gets the count of the conditions.
Public propertyItem
Gets the formatting conidition by index.
Public propertyRangeCount
Gets count of conditionally formatted ranges.
Methods
  NameDescription
Public methodAdd
Adds a formatting condition and effected cell rang to the FormatConditions The FormatConditions can contain up to three conditional formats. References to the other sheets are not allowed in the formulas of conditional formattin
Public methodAddArea
Adds a conditional formatted cell range.
Public methodAddCondition(FormatConditionType)
Add a format condition.
Public methodAddCondition(FormatConditionType, OperatorType, String, String)
Adds a formatting condition.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetCellArea
Gets the conditional formatted cell range by index.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRemoveArea(Int32)
Removes conditional formatted cell range by index.
Public methodRemoveArea(Int32, Int32, Int32, Int32)
Remove conditional formatting int the range.
Public methodRemoveCondition
Removes the formatting condition by index.
Public methodToString (Inherited from Object.)
Examples
[C#]

//Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Sets the conditional format range.
CllArea 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");   

[Visual Basic]

'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