Class FormatConditionCollection

Class FormatConditionCollection

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

Represents conditional formatting. The FormatConditions can contain up to three conditional formats.

public class FormatConditionCollection

Inheritance

objectFormatConditionCollection

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

//Create a new Workbook.
Workbook workbook = new Workbook();

//Get the first worksheet.
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("output.xls");
'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("output.xls")

Properties

Count

Gets the count of the conditions.

public int Count { get; }

Property Value

int

RangeCount

Gets count of conditionally formatted ranges.

public int RangeCount { get; }

Property Value

int

this[int]

Gets the formatting condition by index.

public FormatCondition this[int index] { get; }

Property Value

FormatCondition

Methods

Add(CellArea, FormatConditionType, OperatorType, string, string)

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 formatting.

public int[] Add(CellArea cellArea, FormatConditionType type, OperatorType operatorType, string formula1, string formula2)

Parameters

cellArea CellArea

Conditional formatted cell range.

type FormatConditionType

Type of conditional formatting.It could be one of the members of FormatConditionType.

operatorType OperatorType

Comparison operator.It could be one of the members of OperatorType.

formula1 string

The value or expression associated with conditional formatting.

formula2 string

The value or expression associated with conditional formatting

Returns

int[]

[0]:Formatting condition object index;[1] Effected cell rang index.

AddArea(CellArea)

Adds a conditional formatted cell range.

public int AddArea(CellArea cellArea)

Parameters

cellArea CellArea

Conditional formatted cell range.

Returns

int

Conditional formatted cell rang index.

AddCondition(FormatConditionType, OperatorType, string, string)

Adds a formatting condition.

public int AddCondition(FormatConditionType type, OperatorType operatorType, string formula1, string formula2)

Parameters

type FormatConditionType

The type of format condition.

operatorType OperatorType

The operator type

formula1 string

The value or expression associated with conditional formatting. If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “="=…"”.

formula2 string

The value or expression associated with conditional formatting. The input format is same with formula1

Returns

int

Formatting condition object index;

AddCondition(FormatConditionType)

Add a format condition.

public int AddCondition(FormatConditionType type)

Parameters

type FormatConditionType

Format condition type.

Returns

int

Formatting condition object index;

GetCellArea(int)

Gets the conditional formatted cell range by index.

public CellArea GetCellArea(int index)

Parameters

index int

the index of the conditional formatted cell range.

Returns

CellArea

the conditional formatted cell range

RemoveArea(int)

Removes conditional formatted cell range by index.

public void RemoveArea(int index)

Parameters

index int

The index of the conditional formatted cell range to be removed.

RemoveArea(int, int, int, int)

Remove conditional formatting int the range.

public bool RemoveArea(int startRow, int startColumn, int totalRows, int totalColumns)

Parameters

startRow int

The startRow of the range.

startColumn int

The startColumn of the range.

totalRows int

The number of rows of the range.

totalColumns int

The number of columns of the range.

Returns

bool

Returns TRUE, this FormatCondtionCollection should be removed.

RemoveCondition(int)

Removes the formatting condition by index.

public void RemoveCondition(int index)

Parameters

index int

The index of the formatting condition to be removed.