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

While using the Spreadsheet::ParseExcel::Simple package the below error is coming only for a specific type of excel.:

Use of uninitialized value in unpack at D:/Perl/site/lib/Spreadsheet/P +arseExcel.pm line 1242. substr outside of string at D:/Perl/site/lib/Spreadsheet/ParseExcel.pm + line 1242.


The size of the file is 1.11 MB.

Replies are listed 'Best First'.
Re: Errors while parsing a specific type of Excel File.
by Corion (Patriarch) on Dec 12, 2008 at 10:44 UTC

    This looks as if you're using a weird kind of Excel file that Spreadsheet::ParseExcel cannot parse. Or maybe your program has an error. But you haven't shown us any code, so we can't help you further. Please read the links in SoPW again, which tell you what we need to help you.

    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Errors while parsing a specific type of Excel File.
by gone2015 (Deacon) on Dec 12, 2008 at 11:42 UTC

    The contents of the ParseExcel.pm file are not a secret... I poked at it and found:

    #--------------------------------------------------------------------- +--------- # _subHPageBreak (for Spreadsheet::ParseExcel) DK: P341 #--------------------------------------------------------------------- +--------- sub _subHPageBreak { my($oBook, $bOp, $bLen, $sWk) = @_; my @aBreak; my $iCnt = unpack("v", $sWk); return undef unless(defined $oBook->{_CurSheet}); #BIFF8 if($oBook->{BIFFVersion} >= verBIFF8) { for(my $i=0;$i<$iCnt;$i++) { my($iRow, $iColB, $iColE) = #<<< Line 1242 <<<<<<< +<<<<<<<< unpack('v3', substr($sWk, 2 + $i*6, 6)); # push @aBreak, [$iRow, $iColB, $iColE]; push @aBreak, $iRow; } } #Before BIFF8 else { for(my $i=0;$i<$iCnt;$i++) { my($iRow) = unpack('v', substr($sWk, 2 + $i*2, 2)); push @aBreak, $iRow; # push @aBreak, [$iRow, 0, 255]; } } @aBreak = sort {$a <=> $b} @aBreak; $oBook->{Worksheet}[$oBook->{_CurSheet}]->{HPageBreak} = \@aBreak; }
    where I have marked line 1242. (This is Version: 0.41 of Spreadsheet::ParseExcel.)

    It looks as though the data structure being unpacked is not quite as expected. The warning is telling you that either the spreadsheet or this code is broken (or both, I suppose). This would not give me a warm feeling...

    There is a use warnings at line 10 of the module. I don't know of a way of overriding that from outside the module (but some wiser monk may). All I can suggest is: if you really want to suppress the warning (not that I'd recommend that) you could get out your trusty editor and attack your D:/Perl/site/lib/Spreadsheet/ParseExcel.pm (noting that the warning will come back is this is later updated, of course).

      You can suppress the warnings by using the below code.

      $SIG{'__WARN__'} = \&alarm_handler; # install signal handler to suppre +ss warnings
      sub alarm_handler () { return; }
Re: Errors while parsing a specific type of Excel File.
by mr_mischief (Monsignor) on Dec 12, 2008 at 17:44 UTC
    You say it's a specific type of Excel file, but you don't say what that type is. Is it an Excel XP file? Is it Excel 6? Excel for DOS? A workbook file with charts in it? What makes the file special?
      You can get the file at:

      ftp.s4rec.com/bad.xls
        Well, where do I begin? Lets start with the data in the file. Most employers don't appreciate cost and revenue data being posted openly to the Web. You may want to find another way to answer questions about the problem you're having.

        Your file has 28 different worksheets according to the version of OpenOffice (2.2.1) that I'm running. There's a side-by-side display set up for two of the worksheets (or two worksheet sections at least) in the default view that opens. There's a lot of formatting in pretty much every sheet. I was prompted upon opening it about whether or not I wanted to allow macros to run. In short, it's a quite complex file. I'm not shocked that a free third-party library doesn't quite read it properly, even though the one in question does really well on most Excel files.

        You might need to export some data before working with it. If you can offer, this file might be a good stress test for further work with whatever Excel-reading libraries (such as but not limited to Spreadsheet::ParseExcel) are available. As I said before, it would be good to get clearance for sharing it if you must.

        A reply falls below the community's threshold of quality. You may see it by logging in.
      A reply falls below the community's threshold of quality. You may see it by logging in.