Class FormatCondition
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Represents conditional formatting condition.
public class FormatCondition
Inheritance
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
csharp
[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("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
AboveAverage
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 AboveAverage AboveAverage { get; }
Property Value
ColorScale
Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale.
public ColorScale ColorScale { get; }
Property Value
DataBar
Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar.
public DataBar DataBar { get; }
Property Value
Formula1
Gets and sets the value or expression associated with conditional formatting.
public string Formula1 { get; set; }
Property Value
Remarks
Please add all areas before setting formula. For setting formula for this condition, 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
Gets and sets the value or expression associated with conditional formatting.
public string Formula2 { get; set; }
Property Value
Remarks
Please add all areas before setting formula. For setting formula for this condition, 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: “="=…"”.
IconSet
Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet.
public IconSet IconSet { get; }
Property Value
Operator
Gets and sets the conditional format operator type.
public OperatorType Operator { get; set; }
Property Value
Priority
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 int Priority { get; set; }
Property Value
StopIfTrue
True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;
public bool StopIfTrue { get; set; }
Property Value
Style
Gets or setts style of conditional formatted cell ranges.
public Style Style { get; set; }
Property Value
Text
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 string Text { get; set; }
Property Value
TimePeriod
The applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.
public TimePeriodType TimePeriod { get; set; }
Property Value
Top10
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 Top10 Top10 { get; }
Property Value
Type
Gets and sets whether the conditional format Type.
public FormatConditionType Type { get; set; }
Property Value
Methods
GetFormula1(bool, bool)
Gets the value or expression associated with this format condition.
public string GetFormula1(bool isR1C1, bool isLocal)
Parameters
isR1C1
bool
Whether the formula needs to be formatted as R1C1.
isLocal
bool
Whether the formula needs to be formatted by locale.
Returns
The value or expression associated with this format condition.
GetFormula1(bool, bool, int, int)
Gets the value or expression of the conditional formatting of the cell.
public string GetFormula1(bool isR1C1, bool isLocal, int row, int column)
Parameters
isR1C1
bool
Whether the formula needs to be formatted as R1C1.
isLocal
bool
Whether the formula needs to be formatted by locale.
row
int
The row index.
column
int
The column index.
Returns
The value or expression associated with the conditional formatting of the cell.
Remarks
The given cell must be contained by this conditional formatting, otherwise null will be returned.
GetFormula1(int, int)
Gets the formula of the conditional formatting of the cell.
public string GetFormula1(int row, int column)
Parameters
row
int
The row index.
column
int
The column index.
Returns
The formula.
GetFormula2(bool, bool)
Gets the value or expression associated with this format condition.
public string GetFormula2(bool isR1C1, bool isLocal)
Parameters
isR1C1
bool
Whether the formula needs to be formatted as R1C1.
isLocal
bool
Whether the formula needs to be formatted by locale.
Returns
The value or expression associated with this format condition.
GetFormula2(bool, bool, int, int)
Gets the value or expression of the conditional formatting of the cell.
public string GetFormula2(bool isR1C1, bool isLocal, int row, int column)
Parameters
isR1C1
bool
Whether the formula needs to be formatted as R1C1.
isLocal
bool
Whether the formula needs to be formatted by locale.
row
int
The row index.
column
int
The column index.
Returns
The value or expression associated with the conditional formatting of the cell.
Remarks
The given cell must be contained by this conditional formatting, otherwise null will be returned.
GetFormula2(int, int)
Gets the formula of the conditional formatting of the cell.
public string GetFormula2(int row, int column)
Parameters
row
int
The row index.
column
int
The column index.
Returns
The formula.
SetFormula1(string, bool, bool)
Sets the value or expression associated with this format condition.
public void SetFormula1(string formula, bool isR1C1, bool isLocal)
Parameters
formula
string
The value or expression associated with this format condition. 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: “="=…"”.
isR1C1
bool
Whether the formula is R1C1 formula.
isLocal
bool
Whether the formula is locale formatted.
SetFormula2(string, bool, bool)
Sets the value or expression associated with this format condition.
public void SetFormula2(string formula, bool isR1C1, bool isLocal)
Parameters
formula
string
The value or expression associated with this format condition. 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: “="=…"”.
isR1C1
bool
Whether the formula is R1C1 formula.
isLocal
bool
Whether the formula is locale formatted.
SetFormulas(string, string, bool, bool)
Sets the value or expression associated with this format condition.
public void SetFormulas(string formula1, string formula2, bool isR1C1, bool isLocal)
Parameters
formula1
string
The value or expression associated with this format condition. 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 this format condition. The input format is same with formula1
isR1C1
bool
Whether the formula is R1C1 formula.
isLocal
bool
Whether the formula is locale formatted.