# ****************************************************** # * # * Name: tst-read-xls-file.pl # * # * Design Phase: # * Author: John Miner # * Date: 05/10/2012 # * Purpose: A test program to read xls files. # * # ****************************************************** # Declare all variables use strict; # Include defined module (CPAN) use Spreadsheet::ParseExcel; # Path 2 output file my $file = 'c:\\perl-depot\\xls\\presidents.xls'; # Create instance of module & open file my $parser = Spreadsheet::ParseExcel->new(); # Parse the file my $workbook = $parser->parse($file); if ( !defined $workbook ) { die $parser->error(), ".\n"; } # Open the worksheet my $worksheet = $workbook->worksheet('US Presidents'); # Get the row range my ($row_min, $row_max) = $worksheet->row_range(); # Account for header row $row_min = $row_min + 1; # Process each row for my $row ($row_min .. $row_max) { # id my $cell = $worksheet->get_cell($row, 0); print $cell->value(), ' -', "\n"; # first my $cell = $worksheet->get_cell($row, 1); print " first name = ", $cell->unformatted(), "\n"; # last my $cell = $worksheet->get_cell($row, 2); print " last name = ", $cell->unformatted(), "\n"; # address 1 my $cell = $worksheet->get_cell($row, 3); print " address 1 = ", $cell->unformatted(), "\n"; # address 2 my $cell = $worksheet->get_cell($row, 4); print " address 2 = ", $cell->unformatted(), "\n"; # city my $cell = $worksheet->get_cell($row, 5); print " city = ", $cell->unformatted(), "\n"; # state my $cell = $worksheet->get_cell($row, 6); print " state = ", $cell->unformatted(), "\n"; # zip my $cell = $worksheet->get_cell($row, 7); print " zip = ", $cell->unformatted(), "\n"; # term my $cell = $worksheet->get_cell($row, 8); print " term = ", $cell->unformatted(), "\n"; # extra space print "\n"; print "\n"; }