ConditionalFormattingCollection Class

Encapsulates a collection of FormatCondition objects.
Inheritance Hierarchy
SystemObject
  System.CollectionsCollectionBase
    Aspose.CellsConditionalFormattingCollection

Namespace:  Aspose.Cells
Assembly:  Aspose.Cells (in Aspose.Cells.dll) Version: 20.6.0.0 (20.6)
Syntax
public class ConditionalFormattingCollection : CollectionBase

The ConditionalFormattingCollection type exposes the following members.

Properties
  NameDescription
Public propertyCapacity (Inherited from CollectionBase.)
Public propertyCount (Inherited from CollectionBase.)
Protected propertyInnerList (Inherited from CollectionBase.)
Public propertyItem
Gets the FormatConditions element at the specified index.
Protected propertyList (Inherited from CollectionBase.)
Methods
  NameDescription
Public methodAdd
Adds a FormatConditions to the collection.
Public methodClear (Inherited from CollectionBase.)
Public methodCopy
Copies condtional formattings.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetEnumerator (Inherited from CollectionBase.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnClear (Inherited from CollectionBase.)
Protected methodOnClearComplete (Inherited from CollectionBase.)
Protected methodOnInsert (Inherited from CollectionBase.)
Protected methodOnInsertComplete (Inherited from CollectionBase.)
Protected methodOnRemove (Inherited from CollectionBase.)
Protected methodOnRemoveComplete (Inherited from CollectionBase.)
Protected methodOnSet (Inherited from CollectionBase.)
Protected methodOnSetComplete (Inherited from CollectionBase.)
Protected methodOnValidate (Inherited from CollectionBase.)
Public methodRemoveArea
Remove all conditional formattings in the range.
Public methodRemoveAt (Inherited from CollectionBase.)
Public methodToString (Inherited from Object.)
Examples
[C#]

//Instantiating a Workbook object
Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

//Get Conditional Formattings
ConditionalFormattingCollection cformattings = sheet.ConditionalFormattings;

//Adds an empty conditional formatting
int index = cformattings.Add();

//Get newly added Conditional formatting
FormatConditionCollection fcs = cformattings[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);

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

//Add 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 New Workbook()

Dim sheet As Worksheet = workbook.Worksheets(0)

'Get Conditional Formattings
Dim cformattings As ConditionalFormattingCollection = sheet.ConditionalFormattings

'Adds an empty conditional formatting
Dim index As Integer = cformattings.Add()

'Get newly added Conditional formatting
Dim fcs As FormatConditionCollection = cformattings(index)

'Sets the conditional format range.
Dim ca As 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)

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

'Add 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