FormatCondition class
FormatCondition class
Represents conditional formatting condition.
The FormatCondition type exposes the following members:
Properties
Property | Description |
---|---|
formula1 | Gets and sets the value or expression associated with conditional formatting. |
formula2 | Gets and sets the value or expression associated with conditional formatting. |
operator | Gets and sets the conditional format operator type. |
stop_if_true | True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007; |
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. |
style | Gets or setts style of conditional formatted cell ranges. |
type | Gets and sets whether the conditional format Type. |
icon_set | Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet. |
data_bar | Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar. |
color_scale | Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale. |
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. |
above_average | 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. |
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. |
time_period | The applicable time period in a “date occurring…” conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today. |
Methods
Method | Description |
---|---|
get_formula1 | Gets the value or expression associated with this format condition. |
get_formula1 | Gets the value or expression of the conditional formatting of the cell. |
get_formula1 | Gets the formula of the conditional formatting of the cell. |
get_formula2 | Gets the value or expression associated with this format condition. |
get_formula2 | Gets the value or expression of the conditional formatting of the cell. |
get_formula2 | Gets the formula of the conditional formatting of the cell. |
set_formulas | Sets the value or expression associated with this format condition. |
set_formula1 | Sets the value or expression associated with this format condition. |
set_formula2 | Sets 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
- module
aspose.cells