http://www.perlmonks.org?node_id=1040382

vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Here its my requirement, I need to parse an excel sheet and update the content into database. For this i wrote the following code

sub Parse_Excel { my $Excel_File = shift; unless(defined($Excel_File)){print "Invalid File Name\n";} my $Parser_OBJ = new Spreadsheet::ParseExcel; my $WorkBook = $Parser_OBJ->Parse($Excel_File); if ( !defined $WorkBook ) { die $Parser_OBJ->error(), ".\n"; } my($iR, $iC, $oWkS, $oWkC); print "FILE :", $WorkBook->{File} , "\n"; print "COUNT :", $WorkBook->{SheetCount} , "\n"; print "AUTHOR:", $WorkBook->{Author} , "\n\n" if defined $WorkBoo +k->{Author}; for(my $iSheet=0; $iSheet < $WorkBook->{SheetCount} ; $iSheet++) # +Sheet { $oWkS = $WorkBook->{Worksheet}[$iSheet]; print "SHEET:", $oWkS->{Name}, "\n"; for(my $iR = $oWkS->{MinRow};defined $oWkS->{MaxRow} && $iR <= + $oWkS->{MaxRow};$iR++) # Row { print $oWkS->{MaxRow}."\n"; # prints 12 for(my $iC = $oWkS->{MinCol};defined $oWkS->{MaxCol} && $i +C <= $oWkS->{MaxCol};$iC++) #Column { $oWkC = $oWkS->{Cells}[$iR][$iC]; next if($iR == 0); if($iC == 0) { if ($oWkC){ push(@{$Time_Sheet{Data}->{'date'}},$o +WkC->Value);} else{ push(@{$Time_Sheet{Data}->{'date'}}, " ");} } elsif($iC == 1) { if ($oWkC){push(@{$Time_Sheet{Data}->{'project'}}, +$oWkC->Value);} else{ push(@{$Time_Sheet{Data}->{'project'}}, " ") +;} } elsif($iC == 2) { if($oWkC){push(@{$Time_Sheet{Data}->{'desc'}},$oWk +C->Value);} else{ push(@{$Time_Sheet{Data}->{'desc'}}, " ");} } elsif($iC == 3) { if($oWkC){push(@{$Time_Sheet{Data}->{'hrs'}},$oWkC +->Value);} else{ push(@{$Time_Sheet{Data}->{'hrs'}}, "H");} } } } } }

Here the line  print $oWkS->{MaxRow}."\n"; prints 12, but actually in my excel sheet i have only 6 rows.


All is well