Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: how use Spreadsheet::ParseExcel::Stream;?

by roboticus (Chancellor)
on Jan 24, 2013 at 12:03 UTC ( #1015156=note: print w/replies, xml ) Need Help??

in reply to how use Spreadsheet::ParseExcel::Stream;?


Spreadsheet::ParseExcel::Stream doesn't keep the entire spreadsheet in memory at once. Instead, it reads the spreadsheet row-by-row. So to use it, you have to arrange your logic where you don't dare about any data but the current row. Then, as you call each row, use all the data you need, then proceed to the next row.

# Don't do this! my @defeat_stream; my $xls = Spreadsheet::ParseExcel::Stream->new($xls_file, \%options); while ( my $sheet = $xls->sheet() ) { while ( my $row = $sheet->row ) { # current row now in memory. my @data = @$row; # after this, current row will *disappear*, unless... # you keep the data. push @defeat_stream, $row; } } # Now you either have the entire spreadsheet in memory (defeating the +purpose # of the module), or have run out of memory.

Note: Don't keep all the data around for future use, as I do above, as then you're throwing away the advantage of the module. But since you don't read everything into RAM at once, you could extract what you need, and then iterate over it.


When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: how use Spreadsheet::ParseExcel::Stream;?
by cibien (Novice) on Jan 30, 2013 at 22:01 UTC
    Thankyou very much! I understand now :) but I try with my code and nothing... the xml output is null.
    my $xls = Spreadsheet::ParseExcel::Stream->new($data_folder.$filenam +e, \%options); while ( my $sheet = $xls->sheet() ) { while ( my $row = $sheet->row ) { my @data = @$row; } } for(my $iSheet=0; $iSheet < $xls->{SheetCount} ; $iSheet++) { my $oWkS = $xls->{Worksheet}[$iSheet];
    I'am too much novice in perl to try.. anyway thankyou for your help :)
      the xml output is null.
      What XML output? You're not printing anything. And why do you have this code:
      for(my $iSheet=0; $iSheet < $xls->{SheetCount} ; $iSheet++) { my $oWkS = $xls->{Worksheet}[$iSheet];
      That code is for Spreadsheet::ParseExcel, not Spreadsheet::ParseExcel::Stream.
        Sorry, I'am confused... :( first step in perl...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015156]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2017-04-27 04:19 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (500 votes). Check out past polls.