FormatCondition class

FormatCondition class

Represents conditional formatting condition.

The FormatCondition type exposes the following members:

Properties

PropertyDescription
formula1Gets and sets the value or expression associated with conditional formatting.
formula2Gets and sets the value or expression associated with conditional formatting.
operatorGets and sets the conditional format operator type.
stop_if_trueTrue, no rules with lower priority may be applied over this rule, when this rule evaluates to true.
Only applies for Excel 2007;
priorityThe 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.
styleGets or setts style of conditional formatted cell ranges.
typeGets and sets whether the conditional format Type.
icon_setGet the conditional formatting’s “IconSet” instance.
The default instance’s IconSetType is TrafficLights31.
Valid only for type = IconSet.
data_barGet the conditional formatting’s “DataBar” instance.
The default instance’s color is blue.
Valid only for type is DataBar.
color_scaleGet the conditional formatting’s “ColorScale” instance.
The default instance is a “green-yellow-red” 3ColorScale .
Valid only for type = ColorScale.
top10Get 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.
above_averageGet 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.
textThe text value in a “text contains” conditional formatting rule.
Valid only for type = containsText, notContainsText, beginsWith and endsWith.
The default value is null.
time_periodThe applicable time period in a “date occurring…” conditional formatting rule.
Valid only for type = timePeriod.
The default value is TimePeriodType.Today.

Methods

MethodDescription
get_formula1Gets the value or expression associated with this format condition.
get_formula1Gets the value or expression of the conditional formatting of the cell.
get_formula1Gets the formula of the conditional formatting of the cell.
get_formula2Gets the value or expression associated with this format condition.
get_formula2Gets the value or expression of the conditional formatting of the cell.
get_formula2Gets the formula of the conditional formatting of the cell.
set_formulasSets the value or expression associated with this format condition.
set_formula1Sets the value or expression associated with this format condition.
set_formula2Sets the value or expression associated with this format condition.

Example

from aspose.cells import CellArea, FormatConditionType, OperatorType, Workbook
from aspose.pydrawing import Color

# Instantiating a Workbook object
workbook = Workbook()
sheet = workbook.worksheets[0]
# Adds an empty conditional formatting
index = sheet.conditional_formattings.add()
fcs = sheet.conditional_formattings[index]
# Sets the conditional format range.
ca = CellArea()
ca.start_row = 0
ca.end_row = 0
ca.start_column = 0
ca.end_column = 0
fcs.add_area(ca)
ca = CellArea()
ca.start_row = 1
ca.end_row = 1
ca.start_column = 1
ca.end_column = 1
fcs.add_area(ca)
# Adds condition.
conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100")
# Adds condition.
conditionIndex2 = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100")
# Sets the background color.
fc = fcs[conditionIndex]
fc.style.background_color = Color.red
# Saving the Excel file
workbook.save("output.xls")

See Also