hal9e3
hal9e3

Reputation: 9

Spreadsheet::ParseExcel::SaveParser Issues - Cannot Obtain a Defined Workbook Object

I am trying to use the Spreadsheet::ParseExcel::SaveParser plugin using example code at both metacpan.org and on SO and I cannot define the template (workbook).

I have played around with variations on the new statement, quotes, file parh, etc - nothing works. I put a die after the template statement and it prints the error message. Without that I have either a $template->worksheet() or worksheets() statement and if I skip the die I get a different message. I confirmed that the path to the Excel file is correct. I also new()'ed Spreadsheet::ParseXLSX instead and the code got past the template undefined problem - of course it crashed when I tried to do an AddCell.

    use Spreadsheet::ParseExcel;
    use Spreadsheet::ParseExcel::SaveParser;

    my $saveParser  = Spreadsheet::ParseExcel::SaveParser->new();
    my $template    = $saveParser->Parse("some Excel file verified to exist");
    die "Error! Template not defined!\n" if (!defined($template));

dies

    use Spreadsheet::ParseExcel;
    use Spreadsheet::ParseExcel::SaveParser;

    my $saveParser  = Spreadsheet::ParseExcel::SaveParser->new();
    my $template    = $saveParser->Parse("some Excel file verified to exist");
    my $worksheet = $template->worksheet(0);

Can't call method "worksheet" on an undefined value at ../bin/update_tp.pl line nnn. It also errors out if I use the worksheet name instead of number.

Obviously I expect the $saveParser->Parse command to return a valid object so I can work with it - it doesn't. FYI all modules I'm using are at the current rev of 0.65 except WriteExcel (which isn't relevant yet), which is 2.4.

Upvotes: 0

Views: 342

Answers (1)

Harlan
Harlan

Reputation: 96

Think you'd want to track down what error-handling is available for the Parse() function by reading the CPAN page for this module. Find and adapt that error-handling to give you an inkling of why Parse() would be failing. Your error about "worksheet on an undefined value" is indicative of that call failing. Could be you're not escaping file paths, maybe you don't have read permissions on the file, lots of other reasons Parse() could be failing. Eww, just went and looked myself, and there's fairly inadequate error-handling documented for that function. Maybe try die'ing with some error-handling variables? See https://perldoc.perl.org/perlvar.html#Error-Variables

Upvotes: 0

Related Questions