Documents for Excel, Java Edition Documentation
Features / Conditional Formatting / Data Bar Rule
In This Topic
    Data Bar Rule
    In This Topic

    The data bar rule in conditional formatting displays a bar in the cell on the basis of cell values entered in a range. This rule can be added using the methods of the IDataBar interface.

    Refer to the following example code to add data bar rule to a range of cells in a worksheet.

    Java
    Copy Code
    // Adding Data Bar Rule
    Object[][] data=new Object[][]
    {
        {1},
        {2},
        {3},
        {4},
        {5}
    };
    worksheet.getRange("A1:A5").setValue(data);
            
    IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
            
    dataBar.getMinPoint().setType(ConditionValueTypes.LowestValue);
    dataBar.getMinPoint().setValue(null);
    dataBar.getMaxPoint().setType(ConditionValueTypes.HighestValue);
    dataBar.getMaxPoint().setValue(null);
            
    dataBar.setBarFillType(DataBarFillType.Solid);
    dataBar.getBarColor().setColor(Color.GetGreen());
    dataBar.setDirection(DataBarDirection.Context);
    dataBar.getAxisColor().setColor(Color.GetRed());
    dataBar.setAxisPosition(DataBarAxisPosition.Automatic);
    dataBar.getNegativeBarFormat().setBorderColorType(DataBarNegativeColorType.Color);
    dataBar.getNegativeBarFormat().getBorderColor().setColor(Color.FromArgb(128,0,212));
    dataBar.getNegativeBarFormat().setColorType(DataBarNegativeColorType.Color);
    dataBar.getNegativeBarFormat().getColor().setColor(Color.FromArgb(128,0,240));
    dataBar.setShowValue(false);