daffodil
daffodil

Reputation: 197

Cannot get row_range in perl script

My code doesn't seem to get row_range(). It shows an error which is:

Can't locate object method "row_range" via package "Spreadsheet::ParseExcel::Worksheet" at clamp_init_value.pl line 41.

 #!/usr/bin/perl

 use strict;
 use warnings;
 use Spreadsheet::ParseExcel;

 my $filename = '../../doc/Book1.xls';
 my $parser   = Spreadsheet::ParseExcel->new();
 my $workbook = $parser -> Parse( $filename);

 if ( !defined $workbook ) {
    die "-E-: cannot parse <$filename>.\n";
 }

 for my $worksheet ( $workbook-> Worksheet( 'family pin list' ) ) {

    # Find out the worksheet ranges
    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 ) {

            # Return the cell object at $row and $col
            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

            print "Row, Col    = ($row, $col)\n";
            print "Value       = ", $cell->value(),       "\n";

        }
    }
}

Upvotes: 0

Views: 539

Answers (2)

Dave Cross
Dave Cross

Reputation: 69244

To expand slightly on the answer from TFBW...

The Changes file for this module includes the following entry:

0.43 January 7 2009

    + Restructured and rewrote the main documentation. This is the start of
      a general refactoring. If you would like to keep up to date with it
      keep an eye on the Spreadsheet::ParseExcel Google Group.
      http://groups.google.com/group/spreadsheet-parseexcel

    + Added worksheets() Workbook method to iterate over the Worksheet objects.

    + Added unformatted() method to get a Cell's unformatted value.

    + Renamed public methods RowRange(), ColRange() and Cell() to row_range(),
      col_range() and get_cell(). Old methods are still available.

    ! Turned on compatibility_mode() by default in SaveParser to avoid SP3
      problems.

    ! Fixed minor SaveParser bug with font rotation.
      http://rt.cpan.org/Public/Bug/Display.html?id=41626

So if you have a version of the module that is older than version 0.43, then the method you want is called RowRange(). You can find the version of the module that you have installed by typing this at a command line prompt:

perl -MSpreadsheet::ParseExcel -le'print $Spreadsheet::ParseExcel::VERSION'

If you do have a version of the module that is over ten years old, then I strongly recommend updating it.

Upvotes: 2

TFBW
TFBW

Reputation: 1019

What version of Spreadsheet::ParseExcel::Worksheet is it? Those methods used to be named RowRange() ColRange() and Cell() in the past. See https://metacpan.org/changes/distribution/Spreadsheet-ParseExcel

Upvotes: 1

Related Questions