adamsj has asked for the wisdom of the Perl Monks concerning the following question:

So I've got all these Excel spreadsheet that I don't want to manually enter into a DB one at a time, so I got this nifty module called Spreadsheet::ParseExcel and started learning it.

However, when I do this:

for (my $row = 0; $row <= $tdb->{MaxRow}; $row++) { my $cell = $tdb->{Cells}[$row][0]; my $value = $cell->Value; print FH "$value\n"; }
I'm getting this message: Can't call method "Value" on an undefined value at spacebase.pl line 36.

MaxRow is giving back a value higher than the actual maximum row value. Now, I've come up with a workaround--I'll just wrap my $value = $cell->Value; in an eval and use that to terminate the loop, which is a good idea for other reasons--but I'm curious whether anyone else has experience with this module and knows what might be going on. My guess is that the module is returning a valid number and my spreadsheet is goofy--any other thoughts?

adamsj

They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen

Replies are listed 'Best First'.
Re: Spreadsheet::ParseExcel MaxRow giving funky results
by dvergin (Monsignor) on Jul 13, 2001 at 20:45 UTC
    The error message you are getting would indicate that $row is being left with an undef value after the line

            my $cell = $tdb->{Cells}[$row][0];.

    Have you tried some print statements to trace the value of $cell at that point?

Re: Spreadsheet::ParseExcel MaxRow giving funky results
by dvergin (Monsignor) on Jul 13, 2001 at 19:59 UTC
    A case of code-blindness?   ;-)   Try...

              my $value = $cell->{Value};
     

      Well, that's progress--it sure 'nuff is a mistake1, and fixing it gets rid of the error--but it still gives the wrong value! I'm manually checking spreadsheets to be sure, and it does look wrong.

      1Update: On checking the documentation, I now see that the original form of:

      my $value = $cell->Value;

      was correct--which explains why $value was turning up empty after the change! This is a dead end. Any more thoughts?

      adamsj

      They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen