Sponsored Content
Top Forums Shell Programming and Scripting Perl script to fill the entire row of Excel file with color based on pattern match Post 303022015 by kshitij on Wednesday 22nd of August 2018 11:24:42 PM
Old 08-23-2018
Perl script to fill the entire row of Excel file with color based on pattern match

Hi All ,

I have to write one Perl script in which I need to read one pre-existing xls and based on pattern match for one word in some cells of the XLS , I need to fill the entire row with one color of that matched cell and write the content to another excel

Please find the below stated script which I have written , Unfortunately it is just coloring the particular cell which is being matched but not the entire row.
I am not sure how to extract the rows of the excel based on the pattern match and then fill the color of the designated rows and write to another excel.

Code:
#!/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');
# Add a worksheet
my $worksheet1 = $workbook1->add_worksheet();
#  Add and define a format
my $format = $workbook1->add_format(bg_color => 'green');

for my $worksheet ( $workbook->worksheets() ) {
 
    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();
 
    for my $row ( $row_min .. $row_max ) {
        for my $col ( $col_min .. $col_max ) {
 
            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

    my $string = $cell->value();
      if ($string  =~ m/Completed/i)    { 

$worksheet1->write($row, $col, $cell_value,$format);

   }
else {

 $worksheet1->write($row, $col, $cell->value());
}
}
                 }
    }

This will write the content to another Excel but only the cells having "Completed" word is colored green but not the entire row having the cell "Completed".
Could you help me out in completing this script ?

Thanks and Regards
Kshitij Kulshreshtha
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to match a pattern and print lines

Hi I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9. I appreciate any help with code Thanks Ammu (6 Replies)
Discussion started by: ammu
6 Replies

2. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies

3. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

4. Shell Programming and Scripting

Help needed - Split large file into smaller files based on pattern match

Help needed urgently please. I have a large file - a few hundred thousand lines. Sample CP START ACCOUNT 1234556 name 1 CP END ACCOUNT CP START ACCOUNT 2224444 name 1 CP END ACCOUNT CP START ACCOUNT 333344444 name 1 CP END ACCOUNT I need to split this file each time "CP START... (7 Replies)
Discussion started by: frustrated1
7 Replies

5. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

6. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

7. UNIX for Dummies Questions & Answers

Fill csv entire column with content from another text file

I have a csv that looks like this: ,yude-to-nap2,0,0,0,0,0 ,2twis-yude-to-nap2,0,0,0,0,0 ,2tiws-yude-to-nap2,0,0,0,0,0 ,2arcos-yude-to-nap2,0,0,0,0,0 and another file named m1 that has a single line of text as content: Feb 1 15:30:20 How can I fill the whole the empty column of the... (1 Reply)
Discussion started by: RobertoRivera
1 Replies

8. Shell Programming and Scripting

awk to update value based on pattern match in another file

In the awk, thanks you @RavinderSingh13, for the help in below, hopefully it is close as I am trying to update the value in $12 of the tab-delimeted file2 with the matching value in $1 of the space delimeted file1. I have added comments for each line as well. Thank you :). awk awk '$12 ==... (10 Replies)
Discussion started by: cmccabe
10 Replies

9. UNIX for Beginners Questions & Answers

Match pattern only between certain lines in entire file

Hello, I have input that looks like this: * 0 -1 103 0 0 m. 7 LineNr 23 ClauseNr 1: 1: 1: 304: 0 0 SentenceNr 13 TxtType: Q Pargr: 2.1 ClType:MSyn PS004,006 ZBX= 0 1 1 0 7 -1 -1 3 2 3 2 -1 1 1 -1 -1 -1 -1 0 501 0 PS004,006 ZBX ... (2 Replies)
Discussion started by: jvoot
2 Replies
Spreadsheet::ParseExcel::Worksheet(3pm) 		User Contributed Perl Documentation		   Spreadsheet::ParseExcel::Worksheet(3pm)

NAME
Spreadsheet::ParseExcel::Worksheet - A class for Worksheets. SYNOPSIS
See the documentation for Spreadsheet::ParseExcel. DESCRIPTION
This module is used in conjunction with Spreadsheet::ParseExcel. See the documentation for Spreadsheet::ParseExcel. Methods The "Spreadsheet::ParseExcel::Worksheet" class encapsulates the properties of an Excel worksheet. It has the following methods: $worksheet->get_cell() $worksheet->row_range() $worksheet->col_range() $worksheet->get_name() $worksheet->get_h_pagebreaks() $worksheet->get_v_pagebreaks() $worksheet->get_merged_areas() $worksheet->get_row_heights() $worksheet->get_col_widths() $worksheet->get_default_row_height() $worksheet->get_default_col_width() $worksheet->get_header() $worksheet->get_footer() $worksheet->get_margin_left() $worksheet->get_margin_right() $worksheet->get_margin_top() $worksheet->get_margin_bottom() $worksheet->get_margin_header() $worksheet->get_margin_footer() $worksheet->get_paper() $worksheet->get_start_page() $worksheet->get_print_order() $worksheet->get_print_scale() $worksheet->get_fit_to_pages() $worksheet->is_portrait() $worksheet->is_centered_horizontally() $worksheet->is_centered_vertically() $worksheet->is_print_gridlines() $worksheet->is_print_row_col_headers() $worksheet->is_print_black_and_white() $worksheet->is_print_draft() $worksheet->is_print_comments() get_cell($row, $col) Return the "Cell" object at row $row and column $col if it is defined. Otherwise returns undef. my $cell = $worksheet->get_cell($row, $col); row_range() Returns a two-element list "($min, $max)" containing the minimum and maximum defined rows in the worksheet. If there is no row defined $max is smaller than $min. my ( $row_min, $row_max ) = $worksheet->row_range(); col_range() Returns a two-element list "($min, $max)" containing the minimum and maximum of defined columns in the worksheet. If there is no column defined $max is smaller than $min. my ( $col_min, $col_max ) = $worksheet->col_range(); get_name() The "get_name()" method returns the name of the worksheet. my $name = $worksheet->get_name(); get_h_pagebreaks() The "get_h_pagebreaks()" method returns an array ref of row numbers where a horizontal page break occurs. my $h_pagebreaks = $worksheet->get_h_pagebreaks(); Returns "undef" if there are no pagebreaks. get_v_pagebreaks() The "get_v_pagebreaks()" method returns an array ref of column numbers where a vertical page break occurs. my $v_pagebreaks = $worksheet->get_v_pagebreaks(); Returns "undef" if there are no pagebreaks. get_merged_areas() The "get_merged_areas()" method returns an array ref of cells that are merged. my $merged_areas = $worksheet->get_merged_areas(); Each merged area is represented as follows: [ $start_row, $start_col, $end_row, $end_col] Returns "undef" if there are no merged areas. get_row_heights() The "get_row_heights()" method returns an array_ref of row heights. my $row_heights = $worksheet->get_row_heights(); Returns "undef" if the property isn't set. get_col_widths() The "get_col_widths()" method returns an array_ref of column widths. my $col_widths = $worksheet->get_col_widths(); Returns "undef" if the property isn't set. get_default_row_height() The "get_default_row_height()" method returns the default row height for the worksheet. Generally 12.75. my $default_row_height = $worksheet->get_default_row_height(); get_default_col_width() The "get_default_col_width()" method returns the default column width for the worksheet. Generally 8.43. my $default_col_width = $worksheet->get_default_col_width(); get_header() The "get_header()" method returns the worksheet header string. This string can contain control codes for alignment and font properties. Refer to the Excel on-line help on headers and footers or to the Spreadsheet::WriteExcel documentation for set_header(). my $header = $worksheet->get_header(); Returns "undef" if the property isn't set. get_footer() The "get_footer()" method returns the worksheet footer string. This string can contain control codes for alignment and font properties. Refer to the Excel on-line help on headers and footers or to the Spreadsheet::WriteExcel documentation for set_header(). my $footer = $worksheet->get_footer(); Returns "undef" if the property isn't set. get_margin_left() The "get_margin_left()" method returns the left margin of the worksheet in inches. my $margin_left = $worksheet->get_margin_left(); Returns "undef" if the property isn't set. get_margin_right() The "get_margin_right()" method returns the right margin of the worksheet in inches. my $margin_right = $worksheet->get_margin_right(); Returns "undef" if the property isn't set. get_margin_top() The "get_margin_top()" method returns the top margin of the worksheet in inches. my $margin_top = $worksheet->get_margin_top(); Returns "undef" if the property isn't set. get_margin_bottom() The "get_margin_bottom()" method returns the bottom margin of the worksheet in inches. my $margin_bottom = $worksheet->get_margin_bottom(); Returns "undef" if the property isn't set. get_margin_header() The "get_margin_header()" method returns the header margin of the worksheet in inches. my $margin_header = $worksheet->get_margin_header(); Returns a default value of 0.5 if not set. get_margin_footer() The "get_margin_footer()" method returns the footer margin of the worksheet in inches. my $margin_footer = $worksheet->get_margin_footer(); Returns a default value of 0.5 if not set. get_paper() The "get_paper()" method returns the printer paper size. my $paper = $worksheet->get_paper(); The value corresponds to the formats shown below: Index Paper format Paper size ===== ============ ========== 0 Printer default - 1 Letter 8 1/2 x 11 in 2 Letter Small 8 1/2 x 11 in 3 Tabloid 11 x 17 in 4 Ledger 17 x 11 in 5 Legal 8 1/2 x 14 in 6 Statement 5 1/2 x 8 1/2 in 7 Executive 7 1/4 x 10 1/2 in 8 A3 297 x 420 mm 9 A4 210 x 297 mm 10 A4 Small 210 x 297 mm 11 A5 148 x 210 mm 12 B4 250 x 354 mm 13 B5 182 x 257 mm 14 Folio 8 1/2 x 13 in 15 Quarto 215 x 275 mm 16 - 10x14 in 17 - 11x17 in 18 Note 8 1/2 x 11 in 19 Envelope 9 3 7/8 x 8 7/8 20 Envelope 10 4 1/8 x 9 1/2 21 Envelope 11 4 1/2 x 10 3/8 22 Envelope 12 4 3/4 x 11 23 Envelope 14 5 x 11 1/2 24 C size sheet - 25 D size sheet - 26 E size sheet - 27 Envelope DL 110 x 220 mm 28 Envelope C3 324 x 458 mm 29 Envelope C4 229 x 324 mm 30 Envelope C5 162 x 229 mm 31 Envelope C6 114 x 162 mm 32 Envelope C65 114 x 229 mm 33 Envelope B4 250 x 353 mm 34 Envelope B5 176 x 250 mm 35 Envelope B6 176 x 125 mm 36 Envelope 110 x 230 mm 37 Monarch 3.875 x 7.5 in 38 Envelope 3 5/8 x 6 1/2 in 39 Fanfold 14 7/8 x 11 in 40 German Std Fanfold 8 1/2 x 12 in 41 German Legal Fanfold 8 1/2 x 13 in 256 User defined The two most common paper sizes are "1 = "US Letter"" and "9 = A4". Returns 9 by default. get_start_page() The "get_start_page()" method returns the page number that printing will start from. my $start_page = $worksheet->get_start_page(); Returns 0 if the property isn't set. get_print_order() The "get_print_order()" method returns 0 if the worksheet print "page order" is "Down then over" (the default) or 1 if it is "Over then down". my $print_order = $worksheet->get_print_order(); get_print_scale() The "get_print_scale()" method returns the workbook scale for printing. The print scale fctor can be in the range 10 .. 400. my $print_scale = $worksheet->get_print_scale(); Returns 100 by default. get_fit_to_pages() The "get_fit_to_pages()" method returns the number of pages wide and high that the printed worksheet page will fit to. my ($pages_wide, $pages_high) = $worksheet->get_fit_to_pages(); Returns (0, 0) if the property isn't set. is_portrait() The "is_portrait()" method returns true if the worksheet has been set for printing in portrait mode. my $is_portrait = $worksheet->is_portrait(); Returns 0 if the worksheet has been set for printing in horizontal mode. is_centered_horizontally() The "is_centered_horizontally()" method returns true if the worksheet has been centered horizontally for printing. my $is_centered_horizontally = $worksheet->is_centered_horizontally(); Returns 0 if the property isn't set. is_centered_vertically() The "is_centered_vertically()" method returns true if the worksheet has been centered vertically for printing. my $is_centered_vertically = $worksheet->is_centered_vertically(); Returns 0 if the property isn't set. is_print_gridlines() The "is_print_gridlines()" method returns true if the worksheet print "gridlines" option is turned on. my $is_print_gridlines = $worksheet->is_print_gridlines(); Returns 0 if the property isn't set. is_print_row_col_headers() The "is_print_row_col_headers()" method returns true if the worksheet print "row and column headings" option is turned on. my $is_print_row_col_headers = $worksheet->is_print_row_col_headers(); Returns 0 if the property isn't set. is_print_black_and_white() The "is_print_black_and_white()" method returns true if the worksheet print "black and white" option is turned on. my $is_print_black_and_white = $worksheet->is_print_black_and_white(); Returns 0 if the property isn't set. is_print_draft() The "is_print_draft()" method returns true if the worksheet print "draft" option is turned on. my $is_print_draft = $worksheet->is_print_draft(); Returns 0 if the property isn't set. is_print_comments() The "is_print_comments()" method returns true if the worksheet print "comments" option is turned on. my $is_print_comments = $worksheet->is_print_comments(); Returns 0 if the property isn't set. AUTHOR
Maintainer 0.40+: John McNamara jmcnamara@cpan.org Maintainer 0.27-0.33: Gabor Szabo szabgab@cpan.org Original author: Kawai Takanori kwitknr@cpan.org COPYRIGHT
Copyright (c) 2009-2010 John McNamara Copyright (c) 2006-2008 Gabor Szabo Copyright (c) 2000-2006 Kawai Takanori All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. perl v5.10.1 2010-09-17 Spreadsheet::ParseExcel::Worksheet(3pm)
All times are GMT -4. The time now is 04:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy