Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: set color base on cell's value in your Excel

by blindluke (Hermit)
on Nov 12, 2015 at 14:11 UTC ( [id://1147572]=note: print w/replies, xml ) Need Help??


in reply to set color base on cell's value in your Excel

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

Replies are listed 'Best First'.
Re^2: set color base on cell's value in your Excel
by gbcbooks (Initiate) on Nov 13, 2015 at 05:56 UTC
    ok, one more question is Excel::Writer::XLSX modues's method simliar to Spreadsheet::WriteExcel?

      Even better. To quote the documentation:

      The Excel::Writer::XLSX module is a drop-in replacement for Spreadsheet::WriteExcel.

      It supports practically all the methods in Spreadsheet::WriteExcel, and it adds a lot of new ones, with familiar names and usage.

      For a list of differences, see Compatibility with Spreadsheet::WriteExcel section in the module docs.

      - Luke

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2025-12-08 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (87 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.