I have xls file. I want to change bg_color of particular cells as per some conditions and keeping rest format as it is. For that i use xls rewrite module and it is working fine as per requirement but still doing some extra which i not required. What it is doing extra- some cells in original have pink bg_color these all are getting change with green (which is not required). Here is code snippet. Please help.
use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; my $parser = new Spreadsheet::ParseExcel::SaveParser; my $sheet=1; my $template = $parser->Parse('compare_reports/38_HMI1071_cre_cdo_G.xl +s'); my $worksheet = $template->worksheet($sheet); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $col ( $col_min+2 .. $col_max ) { for my $row ( $row_min+2 .. $row_max ) { #print "\n row, col=$row,$col"; my $cell = $worksheet->get_cell($row, $col); if(!$cell){ next; } elsif($worksheet->get_cell($row,$col)->value() ne "" ){ my $cell_val=$worksheet->get_cell($row,$col)->value(); my $cell_format = $worksheet->get_cell($row,$col)->{Fo +rmatNo}; print "\n row, col=$row,$col cell_format= $cell_format, valu +e= $cell_val"; if($cell_format eq 26){ my $left_val=$worksheet->get_cell(0,$col)->value() +; my $right_val=$worksheet->get_cell(0,$col)->value( +); #Format my $iF1 = $template->AddFont( Name => 'Arial', Height => 11, Bold => 0, #Bold Italic => 0, #Italic Underline => 0, Strikeout => 0, Super => 0, ); my $iFmt = $template->AddFormat( Font => $template->{Font}[$iF1], Fill => [1, 10, 0], # Filled with Red # cf. ParseExcel ( +@aColor) #BdrStyle => [0, 1, 1, 0], #Border Right, To +p #BdrColor => [0, 11, 0, 0], # Right->Green ); $template->AddCell($sheet, 0, $col,$left_val , $iF +mt); $template->AddCell($sheet, 1, $col,$right_val , $i +Fmt); last; } } else { next; } } } my $workbook; { local $^W = 0; $workbook = $template->SaveAs($com_path); } $workbook->close(); push(@temp_files,$_); }

In reply to bg_color color change in xls cells by bimleshsharma

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.