Assuming the keyword might appear in more than one column and anywhere in the row try this

#!/usr/bin/perl use strict; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; my $KEYWORD = 'output'; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('formatting.xls'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $workbook1 = Spreadsheet::WriteExcel->new("perl.xls"); foreach my $worksheet ( $workbook->worksheets() ) { my $name = $worksheet->get_name(); # create worksheet with same name my $worksheet1 = $workbook1->addworksheet($name); my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); next unless ($row_max >= 0 && $col_max >= 0); # skip blank sheets print " PARSING WORKSHEET: $name ROW_MIN = $row_min, ROW_MAX = $row_max; COL_MIN = $col_min, COL_MAX = $col_max "; my $copyflag; my $col1 = 0; for my $col ( $col_min .. $col_max ) { $copyflag = 1; my @rowval = (); for my $row ( $row_min .. $row_max ) { my $cell = $worksheet->get_cell( $row, $col ); next unless defined $cell; my $val = $cell->value(); print "Col, Row, Value = ($col, $row, $val)\n"; $rowval[$row - $row_min] = $val; if ($val =~ /$KEYWORD/i){ print "$KEYWORD found in column $col\n"; $copyflag = 0; } } # copy to new sheet next if ($copyflag == 0); for my $row1 (0..$#rowval){ $worksheet1->write($row1, $col1, $rowval[$row1]); } ++$col1; } }
poj

In reply to Re^13: Deleting entire column in an excel by poj
in thread Deleting entire column in an excel by harishnv

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.