in reply to Re: Out of memory using Spreadsheet::ParseExcel
in thread Out of memory using Spreadsheet::ParseExcel


Could you give some additional information about what is required. It might be helpful to other people faced with the same problem. I've seen questions like this on comp.lang.perl.* as well.

--
John.

  • Comment on Re: Re: Out of memory using Spreadsheet::ParseExcel

Replies are listed 'Best First'.
Re: Re: Re: Out of memory using Spreadsheet::ParseExcel
by dragonchild (Archbishop) on Feb 26, 2002 at 14:05 UTC
    In Spreadsheet/ParseExcel.pm, there's a function called _NewCell(). What I've done is make it look like this:
    sub _NewCell($$$%) { my($oBook, $iR, $iC, %rhKey)=@_; my($sWk, $iLen); return undef unless(defined $oBook->{_CurSheet}); my $oCell = Spreadsheet::ParseExcel::Cell->new( Val => $rhKey{Val}, FormatNo=> $rhKey{FormatNo}, Format => $rhKey{Format}, # Code => $rhKey{Code}, # Type => $oBook->{FmtClass}->ChkType( # $rhKey{Numeric}, # $rhKey{Format}->{FmtIdx}), ); # $oCell->{_Kind} = $rhKey{Kind}; $oCell->{_Value} = $oBook->{FmtClass}->ValFmt($oCell, $oBook); # if($rhKey{Rich}) { # my @aRich = (); # my $sRich = $rhKey{Rich}; # for(my $iWk=0;$iWk<length($sRich); $iWk+=4) { # my($iPos, $iFnt) = unpack('v2', substr($sRich, $iWk)); # push @aRich, [$iPos, $oBook->{Font}[$iFnt]]; # } # $oCell->{Rich} = \@aRich; # } if(defined $_CellHandler) { if(defined $_Object){ no strict; ref($_CellHandler) eq "CODE" ? $_CellHandler->($_Object, $oBook, $oBook->{_CurShe +et}, $iR, $iC, $oCell) : $_CellHandler->callback($_Object, $oBook, $oBook-> +{_CurSheet}, $iR, $iC, $oCell); } else{ $_CellHandler->($oBook, $oBook->{_CurSheet}, $iR, $iC, $oC +ell); } } unless($_NotSetCell) { $oBook->{Worksheet}[$oBook->{_CurSheet}]->{Cells}[$iR][$iC] = $oCell; } return $oCell; }
    Personally, I think that Takanori Kawai didn't fully understand the language when he wrote it.
    1. You don't need Hungarian notation when writing Perl. It obfuscates more than it helps.
    2. The use of prototypes on method calls doesn't do anything but confuse the reader.
    3. Comments that don't really say much. ("Skip Font4" is a direct quote. Why?!?)
    In his defence, it does say that this is an alpha release. I just wish the beta would come out. I could change it, but I don't feel comfortable as I don't know the formatting he's working with.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Thanks for your suggestion .. I editted the module and re-ran the script but got the same out of memory error. I tried commenting out everything except the value, and still got an out of memory error. Frustrating.

      Since it's interpreted, I assume I don't have to re-install the module (run make again). Is that correct?

      --t. alex

      "There was supposed to be an earth-shattering kaboom!" --Marvin the Martian

        That is correct. Now, there are further changes that can be made to Spreadsheet::ParseExcel. One is to remove a lot of font information. Another is to rewrite the objects using file-scoped parallel arrays and not hashes.

        One thing that really helped my understanding of the module was to use Data::Dumper with a relatively small Excel file and see how the workbook was constructed.

        Another memory-saving tip is to reduce the number of worksheets you're using at one time. By consolidating some sheets (easily done using VBA within the workbook), you can drop the memory requirements of Spreadsheet::ParseExcel by over 50%, in some cases.

        Another option is to split up the data into a number of workbooks and work with one at a time.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.