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