SpreadJS Documentation
Setting Conditional Formats

You can set conditional formats for cells.

Using Code

This example sets conditional formats.

JavaScript
Copy Code
$(document).ready(function () {
    var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3});

    //Create respective conditional styles.
    var styleBlue = new GcSpread.Sheets.Style();
    var stylePink = new GcSpread.Sheets.Style();
    var styleLime = new GcSpread.Sheets.Style();
    var styleYellow = new GcSpread.Sheets.Style();
    var styleEmpty = new GcSpread.Sheets.Style();
    styleBlue.backColor = "blue";
    styleBlue.foreColor = "white";
    stylePink.backColor = "pink";
    styleLime.backColor = "lime";
    styleYellow.backColor = "yellow";
    styleEmpty.backColor = undefined;
    styleEmpty.foreColor = undefined;

    //Set conditional formats to respective cells.
    var conditionalFormats = $("#ss").data("spread").getActiveSheet().getConditionalFormats();
    conditionalFormats.addCellValueRule(
        GcSpread.Sheets.ComparisonOperator.EqualsTo,
        0,
        undefined,
        styleEmpty,
        [new GcSpread.Sheets.Range(1, 1, 1, 1)]);
    conditionalFormats.addCellValueRule(
        GcSpread.Sheets.ComparisonOperator.LessThan,
        10,
        undefined,
        styleBlue,
        [new GcSpread.Sheets.Range(1, 1, 1, 1)]);

    conditionalFormats.addCellValueRule(
        GcSpread.Sheets.ComparisonOperator.Between,
        20,
        50,
        stylePink,
        [new GcSpread.Sheets.Range(2, 1, 1, 1)]);

    conditionalFormats.addCellValueRule(
        GcSpread.Sheets.ComparisonOperator.Between,
        50,
        80,
        styleLime,
        [new GcSpread.Sheets.Range(3, 1, 1, 1)]);

    conditionalFormats.addCellValueRule(
        GcSpread.Sheets.ComparisonOperator.GreaterThan,
        80,
        undefined,
        styleYellow,
        [new GcSpread.Sheets.Range(4, 1, 1, 1)]);
});
See Also

Developer's Guide

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.