ag4ve has asked for the wisdom of the Perl Monks concerning the following question:
Perl is returning this error when I try to run this code:
Not a HASH reference at /usr/share/perl5/Spreadsheet/WriteExcel/Worksh +eet.pm line 1798.
And I'm at a loss for where it might be. Also, as I've been faced with this before, what is the best way to track down issues when the error comes from the module itself? I looked at the code there (for the heck of it) - I'm about 99.9% sure I messed up somewhere. My 'messed up' code is below.
#!/usr/bin/perl -T use strict; use warnings; use Carp::Assert; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; use lib '/home/shawn/test/ais'; use DBConnect; my( $infile ) = $ARGV[ 0 ] =~ m/^([\ A-Z0-9_.-]+)$/ig; my( $date ) = $ARGV[ 1 ] =~ m/^([0-9-]+)$/ig; print "infile = $infile\n"; my $sth = $dbh->prepare( 'SELECT * FROM table WHERE field = ? AND YEAR(time) = ?' ) or die "QUERY FAIL: $DBI::errstr\n$!\n"; my @header = ([ "Some", "header", "fields" ]); my $parser = Spreadsheet::ParseExcel->new(); my $workbookin = $parser->parse( $infile ); if ( !defined $workbookin ) { die "Can\'t read spreadsheet: ", $parser->error(), ".\n"; } for( my $sheetcount = 0; $sheetcount < $workbookin->{SheetCount}; $she +etcount++ ) { my($name, $indata, $width) = readws( $sheetcount ); my $outfile = $name =~ /^([\ A-Z0-9_-]+)$/; my $workbookout = Spreadsheet::WriteExcel->new( $outfile . ".xls" ) +; my $worksheetout = $workbookout->add_worksheet( 'Data' ); $worksheetout->write_col( 0, 0, @$indata ); foreach my $row ( 1 .. @$indata) { my $sqldata = sqlget( $indata->[ $row ]->[ 3 ] ); if( $sqldata->[ 0 ] ) { my $worksheetout = $workbookout->add_worksheet( $indata->[ $r +ow ]->[ 0 ] ); foreach my $col ( @$width ) { $worksheetout->set_column( $col, $col, $width->[ $col ] ); } $worksheetout->write_col( 0, 0, \@header ); $worksheetout->write_col( 1, 0, @$sqldata ); } } } sub readws { # Read worksheet - return worksheet n +ame, data, and max cell width my $wsnum = $_[ 0 ]; # Count of input worksheet my $worksheetin = $workbookin->{Worksheet}[ $wsnum ]; my( @xldata, @width ); my( $row_min, $row_max ) = $worksheetin->row_range(); my( $col_min, $col_max ) = $worksheetin->col_range(); my $wsname = $worksheetin->{Name}; # Name of worksheet for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { $width[ $col ] = 0 unless $width[ $col ]; my $cell = $worksheetin->get_cell( $row, $col ); next unless $cell; $xldata[ $row ][ $col ] = $cell->unformatted() ; if( length( $xldata[ $row ][ $col ] ) > $width[ $col ] ) { $width[ $col ] = length( $xldata[ $row ][ $col ] ); } } } return( $wsname, \@xldata, \@width ); } sub sqlget { # Return sql data my $sqlin = $_[ 0 ]; $sth->execute( $sqlin, $date ); my $sqlout = $sth->selectall_arrayref; if( $sth->rows > 0) { return $sqlout; } else { return undef; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Spreadsheet::WriteExcel error
by jmcnamara (Monsignor) on Dec 13, 2010 at 11:03 UTC | |
|
Re: Spreadsheet::WriteExcel error
by ELISHEVA (Prior) on Dec 13, 2010 at 12:05 UTC | |
|
Re: Spreadsheet::WriteExcel error
by Anonyrnous Monk (Hermit) on Dec 13, 2010 at 10:06 UTC |