FormatConditionCollection类

FormatConditionCollection类

表示条件格式。 FormatConditions 最多可以包含三种条件格式。

FormatConditionCollection 类型公开以下成员:

属性

属性描述
count获取条件的数量。
range_count获取条件格式范围的数量。

通过索引获取格式化条件。

索引器

名称描述
[index]要返回的格式化条件的索引。

方法

方法描述
add_condition(self, type, operator_type, formula1, formula2)添加格式化条件。
add_condition(self, type)添加格式条件。
remove_area(self, index)通过索引删除条件格式的单元格范围。
remove_area(self, start_row, start_column, total_rows, total_columns)删除范围内的条件格式。
add(self, cell_area, type, operator_type, formula1, formula2)向 FormatConditions 添加格式化条件和受影响的单元格范围
FormatConditions 最多可以包含三种条件格式。
条件格式的公式中不允许引用其他工作表。
add_area(self, cell_area)添加条件格式的单元格范围。
get_cell_area(self, index)通过索引获取条件格式化的单元格范围。
remove_condition(self, index)通过索引删除格式化条件。

例子

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

# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet.
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")

也可以看看