Aspose::Cells::DataBar class

DataBar class

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

class DataBar

Methods

MethodDescription
DataBar(DataBar_Impl* impl)Constructs from an implementation object.
DataBar(const DataBar& src)Copy constructor.
GetAxisColor()Gets the color of the axis for cells with conditional formatting as data bars.
GetAxisPosition()Gets or sets the position of the axis of the data bars specified by a conditional formatting rule.
GetBarBorder()Gets an object that specifies the border of a data bar.
GetBarFillType()Gets or sets how a data bar is filled with color.
GetColor()Get or set this DataBar’s Color.
GetDirection()Gets or sets the direction the databar is displayed.
GetMaxCfvo()Get or set this DataBar’s max value object. Cannot set null or CFValueObject with type FormatConditionValueType.Min to it.
GetMaxLength()Represents the max length of data bar .
GetMinCfvo()Get or set this DataBar’s min value object. Cannot set null or CFValueObject with type FormatConditionValueType.Max to it.
GetMinLength()Represents the min length of data bar .
GetNegativeBarFormat()Gets the NegativeBarFormat object associated with a data bar conditional formatting rule.
GetShowValue()Get or set the flag indicating whether to show the values of the cells on which this data bar is applied. Default value is true.
IsNull() constChecks whether the implementation object is nullptr.
explicit operator bool() constoperator bool()
operator=(const DataBar& src)operator=
SetAxisColor(const Aspose::Cells::Color& value)Gets the color of the axis for cells with conditional formatting as data bars.
SetAxisPosition(DataBarAxisPosition value)Gets or sets the position of the axis of the data bars specified by a conditional formatting rule.
SetBarFillType(DataBarFillType value)Gets or sets how a data bar is filled with color.
SetColor(const Aspose::Cells::Color& value)Get or set this DataBar’s Color.
SetDirection(TextDirectionType value)Gets or sets the direction the databar is displayed.
SetMaxLength(int32_t value)Represents the max length of data bar .
SetMinLength(int32_t value)Represents the min length of data bar .
SetShowValue(bool value)Get or set the flag indicating whether to show the values of the cells on which this data bar is applied. Default value is true.
ToImage(const Cell& cell, const ImageOrPrintOptions& imgOpts)Render data bar in cell to image byte array.
~DataBar()Destructor.

Fields

FieldDescription
_implThe implementation object.

Examples

Aspose::Cells::Startup();
//Instantiating a Workbook object
Workbook workbook;

Worksheet sheet = workbook.GetWorksheets().Get(0);

//Adds an empty conditional formatting
int index = sheet.GetConditionalFormattings().Add();

FormatConditionCollection fcs = sheet.GetConditionalFormattings().Get(index);

//Sets the conditional format range.
CellArea ca;
ca.StartRow = 0;
ca.EndRow = 2;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);

//Adds condition.
int idx = fcs.AddCondition(FormatConditionType::DataBar);

fcs.AddArea(ca);

FormatCondition cond = fcs.Get(idx);

//Get Databar
DataBar dataBar = cond.GetDataBar();

dataBar.SetColor(Color{ 0xff, 0xff, 0xa5, 0 });

//Set Databar properties
dataBar.GetMinCfvo().SetType(FormatConditionValueType::Percentile);

dataBar.SetShowValue(false);

dataBar.GetBarBorder().SetType(DataBarBorderType::Solid);

dataBar.GetBarBorder().SetColor(Color{ 0xff, 0xdd, 0xa0, 0xdd });//Plum

dataBar.SetBarFillType(DataBarFillType::Solid);

dataBar.SetAxisColor(Color{ 0xff, 0xff, 0, 0 });//Red

dataBar.SetAxisPosition(DataBarAxisPosition::Midpoint);

dataBar.GetNegativeBarFormat().SetColorType(DataBarNegativeColorType::Color);

dataBar.GetNegativeBarFormat().SetColor(Color{ 0xff, 0xff, 0xff, 0xff });//White

dataBar.GetNegativeBarFormat().SetBorderColorType(DataBarNegativeColorType::Color);

dataBar.GetNegativeBarFormat().SetBorderColor(Color{ 0xff, 0xff, 0xff, 0 });//Yellow

//Put Cell Values
Cell cell1 = sheet.GetCells().Get(u"A1");
cell1.PutValue(10);

Cell cell2 = sheet.GetCells().Get(u"A2");
cell2.PutValue(120);

Cell cell3 = sheet.GetCells().Get(u"A3");
cell3.PutValue(260);

//Saving the Excel file
workbook.Save(u"book1.xlsx");

Aspose::Cells::Cleanup();

See Also