Perl: Read Excel Cell Value


A sample code to read excel cell value by using Spreadsheet::ParseExcel module.

#!/user/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;

#Parse excel file
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse(“test.xls”);

#Get cell value from excel sheet1 row 1 column 2
my $worksheet = $workbook->worksheet(‘sheet1’);
my $cell = $worksheet->get_cell(1,2);

# Print the cell value when not blank
if ( defined $cell and $cell->value() ne ”  ) {               
my $value = $cell->value();
print “cell value is $value \n”;
}

2 thoughts on “Perl: Read Excel Cell Value

  1. If i leave out that test like if(defined($cell)) i get an error when i try to process blank cells.
    But if i do put it in, all $cell fail the test.
    ???
    So if i leave it out i get most of my work done but it crashes at the end.
    If i put it in, the code just never executes $cell->value()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s