I am using Spreadsheet::WriteExcel in my code. I need conditional formatting in the sense that if certain conditions are fulfilled the background color should change.
My code goes something like this -
But, it is not working. Can you pl. help me with it? Thanks in advance...
my $workbook = Spreadsheet::WriteExcel->new($file_name);
my $worksheet = $workbook->add_worksheet();
my $format_heading = $workbook->add_format();
my $condition = "some value";
getFormat($condition);
$worksheet->write($row_position, $column_position, $some_info,$format_
+heading);
sub getFormat {
$condition = shift;
if (Condition 1){
$format_heading->set_bgcolor('yellow');
}
elsif (Condition 2){
$format_heading->set_bgcolor('pink');
$format_heading->set_color('red');
}
elsif (Condition 3){
$format_heading->set_bgcolor('blue');
}
else {
$format_heading->set_bgcolor('white'); # Default color
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.