Conditional formatting: highlighting cells that more than the specified value

This example highlights cells whose values are greater than the specified value (90) with the light green background in the range C4:C11. It's possible to use any operator from CFormatOperator enum.



#include "libxl.h"

using namespace libxl;

int main()
{
    Book* book = xlCreateXMLBook();    
    
    Sheet* sheet = book->addSheet(L"my");

    sheet->writeStr(2, 1, L"Country");
    sheet->writeStr(2, 2, L"Road injures");
    sheet->writeStr(3, 1, L"USA");
    sheet->writeStr(4, 1, L"UK");
    sheet->writeStr(5, 1, L"Switzerland");
    sheet->writeStr(6, 1, L"Spain");
    sheet->writeStr(7, 1, L"Italy");
    sheet->writeStr(8, 1, L"London");
    sheet->writeStr(9, 1, L"Greece");
    sheet->writeStr(10, 1, L"Japan");

    sheet->writeNum(3, 2, 64);
    sheet->writeNum(4, 2, 94);
    sheet->writeNum(5, 2, 88);
    sheet->writeNum(6, 2, 93);
    sheet->writeNum(7, 2, 86);
    sheet->writeNum(8, 2, 75);
    sheet->writeNum(9, 2, 67);
    sheet->writeNum(10, 2, 91);    

    ConditionalFormat* cFormat = book->addConditionalFormat();
    cFormat->setFillPattern(FILLPATTERN_SOLID);
    cFormat->setPatternBackgroundColor(COLOR_LIGHTGREEN);

    ConditionalFormatting* cf = sheet->addConditionalFormatting();
    cf->addRange(3, 10, 2, 2);
    cf->addOpNumRule(CFOPERATOR_GREATERTHAN, cFormat, 90);
   
    book->save(L"out.xlsx");

    book->release();
    
    return 0;
}

See also: