shilpam, the problem is you are using 'pink' color, which sets white color, you try someother color in that condition. But as per your logic the condition which get satisfied at last will be set as background color for rest.
If i understood your requirement correctly, the following coding exactly doing your job. But as far as efficiency of the code, i cant guarantee you. You can minimize the following code.
use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("test.xls"); my $worksheet = $workbook->add_worksheet(); my $format_heading1 = $workbook->add_format(); my $format_heading2 = $workbook->add_format(); my $format_heading3 = $workbook->add_format(); my $format_heading4 = $workbook->add_format(); my $condition = "a"; getFormat1($condition); $worksheet->write("A1", "sometext", $format_heading1); $condition = "c"; getFormat2($condition); $worksheet->write("A2", "sometext", $format_heading2); $condition = "d"; getFormat3($condition); $worksheet->write("A3", "sometext", $format_heading3); $condition = "b"; getFormat4($condition); $worksheet->write("A4", "sometext", $format_heading4); sub getFormat1 { $condition = shift; if ($condition eq 'a'){ $format_heading1->set_bg_color('yellow'); } elsif ($condition eq 'b'){ $format_heading1->set_bg_color('red'); } elsif ($condition eq 'c'){ $format_heading1->set_bg_color('blue'); } else { $format_heading1->set_bg_color('green'); # Default color } } sub getFormat2 { $condition = shift; if ($condition eq 'a'){ $format_heading2->set_bg_color('yellow'); } elsif ($condition eq 'b'){ $format_heading2->set_bg_color('red'); } elsif ($condition eq 'c'){ $format_heading2->set_bg_color('blue'); } else { $format_heading2->set_bg_color('green'); # Default color } } sub getFormat3 { $condition = shift; if ($condition eq 'a'){ $format_heading3->set_bg_color('yellow'); } elsif ($condition eq 'b'){ $format_heading3->set_bg_color('red'); } elsif ($condition eq 'c'){ $format_heading3->set_bg_color('blue'); } else { $format_heading3->set_bg_color('green'); # Default color } } sub getFormat4 { $condition = shift; if ($condition eq 'a'){ $format_heading4->set_bg_color('yellow'); } elsif ($condition eq 'b'){ $format_heading4->set_bg_color('red'); } elsif ($condition eq 'c'){ $format_heading4->set_bg_color('blue'); } else { $format_heading4->set_bg_color('green'); # Default color } }
Cheers!!! :)
Prasad
In reply to Re^3: Conditional Formatting with Spreadsheet::WriteExcel
by prasadbabu
in thread Conditional Formatting with Spreadsheet::WriteExcel
by shilpam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |