On Feb 12, 4:51 pm, pomoxp <
pom...@gmail.com> wrote:
> Hello
>
> I have an issue when I try to parse 2 files using different methods
> like this :
> a) parse first file with a CellHandler
> b) parse second file without specifying CellHandler
Hi Pascal,
I wasn't aware of it but that is definitely a bug.
The CellHandler sub ref is stored in a package/class variable so it is
reused between parsers!!
You can work around it for now by changing
my $_CellHandler;
to
our $_CellHandler;
is ParseExcel.pm and then resetting it in your program as follows:
$Spreadsheet::ParseExcel::_CellHandler = undef;
Here is a complete example based on yours:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $parser1 = Spreadsheet::ParseExcel->new(
CellHandler => \&cell_handler_conversion_file,
NotSetCell => 1
);
my $workbook1 = $parser1->Parse('Book1.xls')
or die "could not parse excel file";
# Add this.
$Spreadsheet::ParseExcel::_CellHandler = undef;
## PARSE second file
my $parser2 = Spreadsheet::ParseExcel->new();
my $workbook2 = $parser2->Parse('Book2.xls');
for my $worksheet ( $workbook2->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
ROW: for my $row ( $row_min + 2 .. $row_max ) {
COL: for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print "LINE ", $cell->value(), "\n";
}
}
}
sub cell_handler_conversion_file {
my $workbook = $_[0];
my $sheet_index = $_[1];
my $row = $_[2];
my $col = $_[3];
my $cell = $_[4];
print "Cell handler: ", $cell->unformatted(), "\n";
}
__END__
John.
--