DataBar class

DataBar class

Describe the DataBar conditional formatting rule. This conditional formatting rule displays a gradated data bar in the range of cells.

The DataBar type exposes the following members:

Properties

PropertyDescription
axis_colorGets the color of the axis for cells with conditional formatting as data bars.
axis_positionGets or sets the position of the axis of the data bars specified by a conditional formatting rule.
bar_fill_typeGets or sets how a data bar is filled with color.
directionGets or sets the direction the databar is displayed.
bar_borderGets an object that specifies the border of a data bar.
negative_bar_formatGets the NegativeBarFormat object associated with a data bar conditional formatting rule.
min_cfvoGet or set this DataBar’s min value object.
Cannot set null or CFValueObject with type FormatConditionValueType.Max to it.
max_cfvoGet or set this DataBar’s max value object.
Cannot set null or CFValueObject with type FormatConditionValueType.Min to it.
colorGet or set this DataBar’s Color.
min_lengthRepresents the min length of data bar .
max_lengthRepresents the max length of data bar .
show_valueGet or set the flag indicating whether to show the values of the cells on which this data bar is applied.
Default value is true.

Methods

MethodDescription
to_imageRender data bar in cell to image byte array.

Example

from aspose.cells import CellArea, DataBarAxisPosition, DataBarBorderType, DataBarFillType, DataBarNegativeColorType, FormatConditionType, FormatConditionValueType, 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 = 2
ca.start_column = 0
ca.end_column = 0
fcs.add_area(ca)
# Adds condition.
idx = fcs.add_condition(FormatConditionType.DATA_BAR)
fcs.add_area(ca)
cond = fcs[idx]
# Get Databar
dataBar = cond.data_bar
dataBar.color = Color.orange
# Set Databar properties
dataBar.min_cfvo.type = FormatConditionValueType.PERCENTILE
dataBar.min_cfvo.value = 30
dataBar.show_value = False
dataBar.bar_border.type = DataBarBorderType.SOLID
dataBar.bar_border.color = Color.plum
dataBar.bar_fill_type = DataBarFillType.SOLID
dataBar.axis_color = Color.red
dataBar.axis_position = DataBarAxisPosition.MIDPOINT
dataBar.negative_bar_format.color_type = DataBarNegativeColorType.COLOR
dataBar.negative_bar_format.color = Color.white
dataBar.negative_bar_format.border_color_type = DataBarNegativeColorType.COLOR
dataBar.negative_bar_format.border_color = Color.yellow
# Put Cell Values
cell1 = sheet.cells.get("A1")
cell1.put_value(10)
cell2 = sheet.cells.get("A2")
cell2.put_value(120)
cell3 = sheet.cells.get("A3")
cell3.put_value(260)
# Saving the Excel file
workbook.save("book1.xlsx")

See Also