Other API Samples

Live SpreadsheetGear API Samples

Range Samples Conditional Formats Custom Expression

Demonstrates using a custom Expression-based Conditional Format to highlight data rows based on whether the Expression evaluates to true or false. In this case, all versions of .NET that were released in the month of November for any given year will be highlighted.

// Open workbook with a data range that will be formatted with a conditional format.
SpreadsheetGear.IWorkbook workbook = 
    SpreadsheetGear.Factory.GetWorkbook(@"Files/AlternatingRowColorSampleData.xlsx");
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;

// Get range that Conditional Formatting will be applied to.
SpreadsheetGear.IRange dataRange = worksheet.Cells["A2:B24"];

// Create an Expression-based conditional format that locates any release date
// in November.
SpreadsheetGear.IFormatCondition cf = dataRange.FormatConditions.Add(
    SpreadsheetGear.FormatConditionType.Expression,
    SpreadsheetGear.FormatConditionOperator.None, @"=ISNUMBER(SEARCH(""November"",$B2))",
    null);

// For every other row, apply a highlight-like Theme Color
cf.Interior.ThemeColor = SpreadsheetGear.Themes.ColorSchemeIndex.Accent4;
cf.Interior.TintAndShade = 0.8;  // 80% lighter
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.


Supporting Files

The following files are utilized by this sample: