Here are two examples, adapted from the Spreadsheet::ParseExcel documentation, showing how to iterate through all sheets and to access just one sheet:
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
# Iterate through all worksheets, show value at A1
for my $worksheet ( $workbook->worksheets() ) {
next unless my $cell = $worksheet->get_cell( 0, 0 ); # row, col
print 'Worksheet: '
. $worksheet->get_name()
. '; A1: '
. $cell->value() . "\n";
}
print "\n";
# Get only one sheet, show value at A1
if ( my $worksheet = $workbook->worksheet('Sheet5') ) { # Can be in
+dex 0-4, in this example
if ( my $cell = $worksheet->get_cell( 0, 0 ) ) { # row, col
print 'Worksheet: '
. $worksheet->get_name()
. '; A1: '
. $cell->value() . "\n";
}
}
Output:
Worksheet: Sheet1; A1: 42
Worksheet: Sheet2; A1: 21
Worksheet: Sheet3; A1: 17
Worksheet: Sheet4; A1: 58
Worksheet: Sheet5; A1: 100
Worksheet: Sheet5; A1: 100
Hope this helps! |