http://www.perlmonks.org?node_id=972173

bimleshsharma has asked for the wisdom of the Perl Monks concerning the following question:

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,$_); }