in reply to Help with Spreadsheet::ParseExcel

Try to separate your CGI from your Excel code. Just try running this simplified code. You should see the worksheet names printed:
use warnings; use strict; use Spreadsheet::ParseExcel; my $f_to_parse = "accounts.xls"; my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($f_to_parse); for my $sheet (@{$workbook->{Worksheet}}) { print "Sheet: ", $sheet->{Name}, "\n"; }
Side note: The following code will not die if the file does not exist. Try it yourself:
my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($f_to_parse)or + die "Unable to open $f_to_parse\n";
Refer to Spreadsheet::ParseExcel (the error method).

Replies are listed 'Best First'.
Re^2: Help with Spreadsheet::ParseExcel
by Anonymous Monk on Jan 11, 2011 at 18:21 UTC
    Hi, it didn't make any difference with or without CGI, I fixed the "die" method as well, but I still have the problem with the code I posted, any suggestion?
    #!/usr/bin/perl -w use strict; use CGI qw( -oldstyle_urls :standard ); use CGI::Carp qw ( fatalsToBrowser ); use Spreadsheet::ParseExcel; my $f_to_parse = "accounts.xls"; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($f_to_parse); #my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($f_to_parse)o +r die "Unable to open $f_to_parse\n"; if ( !defined $workbook ) { die "Got error code ", $parser->error_code, ".\n"; } for my $sheet (@{$workbook->{Worksheet}}) { print "Sheet: ", $sheet->{Name}, "\n"; } #Result: #Sheet: Sheet1 #Sheet: Sheet2 #Sheet: Sheet3

    Thanks!
      Great. So, you proved that something will get printed. Now, start adding your lines of code back in and debug with print statements to see where things start going wrong. Refer to the Basic debugging checklist for other tips.