I would like to find out the last row containing data in a particualar column.

That information isn't stored in an Excel file. Excel only stores the maximum and minimum row and column for the entire worksheet.

If you want to find individual maximum values for a column with Spreadsheet::ParseExcel you will have to iterate through all the rows. Here is a generalised example.

#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $filename = $ARGV[0] or die "Parsing error: must specify filena +me.\n"; my $workbook = $parser->parse( $filename ); die "Parsing error: ", $parser->error(), ".\n" if !defined $workbo +ok; # Select a particular worksheet. my $worksheet = $workbook->worksheet( 0 ); # Get the worksheet cell range. my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); # Store the individual column maxima. my @col_maxes; for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); if ( defined $cell && $cell->value() ne '' ) { $col_maxes[$col] = $row; } } } # The rows and columns are zero indexed and columns that don't con +tain # data and thus don't have a maximum value will be undef. The foll +owing # prints out the data in Excel 1-indexed style. my $col_name = 'A'; for my $max ( @col_maxes ) { if ( defined $max ) { $max = $max + 1; } else { $max = 0; } print "Column '$col_name' max row = $max\n"; $col_name++; } __END__ For a spreadsheet like this: ________ _| Sheet1 |__________________________________________________ |_____________________________________________________________ +| | || | | +| | || A | B | C +| |_________||________________|________________|________________ +| | 1 || Foo | | +| |_________||________________|________________|________________ +| | 2 || | | Foo +| |_________||________________|________________|________________ +| | 3 || Foo | | +| |_________||________________|________________|________________ +| | 4 || | | Foo +| |_________||________________|________________|________________ +| Prints this: Columm 'A' max row = 3 Columm 'B' max row = 0 Columm 'C' max row = 4

--
John.


In reply to Re: Reading Excel spreadsheets... by jmcnamara
in thread Reading Excel spreadsheets... by biswanath_c

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.