Document Solutions for Excel, .NET Edition | Document Solutions
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 properties and methods of the IDataBar interface.

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

    C#
    Copy Code
    // Adding Databar rule
    worksheet.Range["A1:A5"].Value = new object[,]
    {
        {1},
        {2},
        {3},
        {4},
        {5}
    };
    
    IDataBar dataBar = worksheet.Range["A1:A5"].FormatConditions.AddDatabar();
    
    dataBar.MinPoint.Type = ConditionValueTypes.LowestValue;
    dataBar.MinPoint.Value = null;
    dataBar.MaxPoint.Type = ConditionValueTypes.HighestValue;
    dataBar.MaxPoint.Value = null;
    
    dataBar.BarFillType = DataBarFillType.Solid;
    dataBar.BarColor.Color = Color.Green;
    dataBar.Direction = DataBarDirection.Context;
    dataBar.AxisColor.Color = Color.Red;
    dataBar.AxisPosition = DataBarAxisPosition.Automatic;
    dataBar.NegativeBarFormat.BorderColorType = DataBarNegativeColorType.Color;
    dataBar.NegativeBarFormat.BorderColor.Color = Color.FromArgb(128, 0, 212);
    dataBar.NegativeBarFormat.ColorType = DataBarNegativeColorType.Color;
    dataBar.NegativeBarFormat.Color.Color = Color.FromArgb(128, 0, 240);
    dataBar.ShowValue = false;