The main drawback to the Spreadsheet::ParseExcel callback interface is that it gets called for every cell. It would be nice if the callbacks could process the data row by row (when desired). So here is an implementation that does that. And it has the advantage over the OP that no Coro is necessary:
package Spreadsheet::ParseExcel::CB; use strict; use warnings; use Spreadsheet::ParseExcel; sub new { my $class = shift; my %args = @_; my $sheet_f = $args{Sheet}; my $row_f = $args{Row}; bless { Sheet => $sheet_f, Row => $row_f, }, $class; } sub parse { my ($self,$file) = @_; my $row_f = $self->{Row}; my $sheet_f = $self->{Sheet}; my @cells; my $sheet = ''; my ($wb, $idx, $row, $col, $cell); my ($prv_idx, $prv_row) = (-1,-1); my $handler = sub { ($wb, $idx, $row, $col, $cell) = @_; if ( $prv_row >= 0 and ( $row > $prv_row or $idx > $prv_idx ) ) { $row_f->(@cells) if $row_f; @cells = (); } if ($idx > $prv_idx) { if ($sheet_f) { my $ws = $wb->worksheet($idx); $sheet_f->($ws->{Name}, $ws, $wb); } } push @cells, $cell; ($prv_idx, $prv_row) = ($idx, $row); }; my $xls = Spreadsheet::ParseExcel->new( CellHandler => $handler, NotSetCell => 1, ); $xls->Parse($file); # Last row $row_f->(@cells) if $row_f; } 1; ## And some sample code: #!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel::CB; my $name; my $process_row = sub { my @vals = map $_->value(), @_; print "$name: @vals\n"; }; my $process_sheet = sub { $name = shift; print "Sheet: $name\n"; }; my $xls = PM::ParseExcel::CB->new( Row => $process_row, Sheet => $process_sheet, ); $xls->parse('spreadsheet.xls')

In reply to Re: RFC: Spreadsheet::ParseExcel::Stream by runrig
in thread RFC: Spreadsheet::ParseExcel::Stream by runrig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.