in reply to Perl script to fill the entire row of Excel file with color based on pattern match
Read a complete row and store the values in an array. Then write a complete row.
poj#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('status.xls'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $workbook1 = Spreadsheet::WriteExcel->new('Report.xls'); my $format = $workbook1->add_format(bg_color => 'green'); for my $worksheet ( $workbook->worksheets() ) { my $worksheet1 = $workbook1->add_worksheet(); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { my @value = (); my $fmt; # format for complete row # store row in array for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); if (defined $cell) { $value[$col] = $cell->value() ; $fmt = $format if ($value[$col] =~ m/Completed/i) } } # write row for my $col ( $col_min .. $col_max ) { $worksheet1->write($row, $col, $value[$col],$fmt); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl script to fill the entire row of Excel file with color based on pattern match
by kshitij (Sexton) on Aug 29, 2018 at 12:55 UTC | |
by poj (Abbot) on Aug 29, 2018 at 13:09 UTC | |
by kshitij (Sexton) on Aug 30, 2018 at 08:36 UTC | |
by poj (Abbot) on Aug 30, 2018 at 12:30 UTC | |
by kshitij (Sexton) on Aug 31, 2018 at 04:17 UTC | |
|