Other API Samples

Live SpreadsheetGear API Samples

Range Samples Conditional Formats Data Bar

Create a Data Bar Conditional Format.

// Create a new workbook and some local variables.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;

// Add a title to a cell.
cells["A1"].Formula = "Data Bar";

// Get a reference to a range of cells.
SpreadsheetGear.IRange range = cells["A2:A11"];

// Load data and format as $ using multiple cell range.
range.Formula = "=ROW() * 10 - 10";
range.NumberFormat = "$#,##0_);($#,##0)";

// Get a reference to the range's conditional formats collection.
SpreadsheetGear.IFormatConditions conditions = range.FormatConditions;

// Add data bar conditional format.
SpreadsheetGear.IFormatCondition condition = conditions.AddDatabar();

// Get a reference to the data bar condition.
SpreadsheetGear.IDatabar dataBar = condition.Databar;

// Get a reference to the data bar border and apply formatting.
SpreadsheetGear.IDataBarBorder barBorder = dataBar.BarBorder;
barBorder.Type = SpreadsheetGear.DataBarBorderType.Solid;
barBorder.Color.ThemeColor = SpreadsheetGear.Themes.ColorSchemeIndex.Accent1;

// Set min and max scale values.
dataBar.MinPoint.Modify(SpreadsheetGear.ConditionValueTypes.Number, 0);
dataBar.MaxPoint.Modify(SpreadsheetGear.ConditionValueTypes.Number, 100);
Run This Sample
Render Image

Generate an image representation of the results of this sample, which uses the SpreadsheetGear.Drawing.Image class to convert ranges, charts and shapes to images.

Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.