Skip Menu |

This queue is for tickets about the Spreadsheet-ParseExcel-Simple CPAN distribution.

Report information
The Basics
Id: 9175
Status: resolved
Priority: 0/
Queue: Spreadsheet-ParseExcel-Simple

People
Owner: Nobody in particular
Requestors: jmcnamara [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: 1.02



Date: Wed, 01 Sep 2004 22:26:27 +0200
To: tony [...] tmtm.com
From: John McNamara <jmcnamara [...] cpan.org>
Subject: Spreadsheet::ParseExcel::Simple
Hi Tony,

There is a small bug in Spreadsheet::ParseExcel::Simple where has_data() returns false when there is data in only the first row. The following program demonstrates:



    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;
    use Spreadsheet::ParseExcel::Simple;


    my $workbook   = Spreadsheet::WriteExcel->new("test.xls");
    my $worksheet1 = $workbook->add_worksheet();
    my $worksheet2 = $workbook->add_worksheet();

    $worksheet1->write('A1', 'Hello'); # 1 row

    $worksheet2->write('A1', 'Hello'); # 2 rows
    $worksheet2->write('A2', 'Hello');

    $workbook->close();


    my $xls = Spreadsheet::ParseExcel::Simple->read('test.xls');

    for my $sheet ($xls->sheets) {
        print $sheet->{sheet}->{Name}, ' ',
              $sheet->has_data ? 'has' : "hasn't", " data.\n";
    }

    __END__

    Prints:
       Sheet1 hasn't data.
       Sheet2 has data.



I doubt if you need any help to figure this out but just to save you a little time the problem is here:

    sub has_data {
      my $self = shift;
      $self->{sheet}->{MaxRow} and ...
    }

Spreadsheet::ParseExcel's MaxRow property is 0 for 1 row and undef for zero rows. Adding a defined() will fix it:


    sub has_data {
      my $self = shift;
      defined $self->{sheet}->{MaxRow} and ...
    }

See you at YAPC in a couple of weeks. I'm looking forward to it. :-)

John.
--