Welcome to the monastery, gbcbooks!

What you are trying to do is called conditional formatting. You want to format the cells in a certain way (set background colour), when a certain condition is met.

Unfortunately, the module you are using has very limited support for conditional formatting. Basically, you can only set the color tags for negative and positive values, like this:

my $f_change = $workbook->add_format(); $f_change->set_num_format('[Green]0.0%;[Red]-0.0%;0.0%'); $worksheet->write(2, 3, -0.015, $f_change); # negative, will be printe +d in red

If you want conditional formatting, I can only suggest that you switch to Excel::Writer::XLSX. It does exactly what you want, has excellent documentation, and a lot of examples, including an example for conditional formatting.

Good luck!

- Luke


In reply to Re: set color base on cell's value in your Excel by blindluke
in thread set color base on cell's value in your Excel by gbcbooks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.