I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations.
In this process, I first defined 10 records in excel sheet and executed the below code.
In the first run it is OK. But after deleting last few rows in excel sheet and then running, blank lines are displayed at the end.
#!C:\perl\bin �w
use strict;
use Spreadsheet::ParseExcel;
my $FileName = "C:/pro1/birthdays.xls";
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse($FileName);
die $parser->error(), ".\n" if ( !defined $workbook );
# Following block is used to Iterate through all worksheets
# in the workbook and print the worksheet content
for my $worksheet ( $workbook->worksheets() ) {
# Find out the worksheet ranges
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
# Return the cell object at $row and $col
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
}
}
}
---------- Post updated at 06:46 AM ---------- Previous update was at 06:33 AM ----------
Its done..
applied if condition to check the string whether null or not
$temp = $cell->value();
if ($temp ne "")
{
print "Value = ", $cell->value(), "\n";
}