Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

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


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

cibien:

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.

...roboticus

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


Comment on Re: how use Spreadsheet::ParseExcel::Stream;?
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-07-31 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls