-1

I have a perl script which extracts rows from many Excel spreadsheets in a directory, however, it's not working due to some error messages: enter image description here

I didn't know why I had this error since I only used Spreadsheet::ParseExcel::Simple twice in my script:

  1. use Spreadsheet::ParseExcel::Simple;

  2. my $xls = Spreadsheet::ParseExcel::Simple->read($exxfilename);

Here's the whole chunk of code for your reference:

 # Get rows from many Excel spreadsheets in a directory
###################################
 #! /usr/local/bin/perl -w
use strict;
use Spreadsheet::ParseExcel::Simple;

#----------------------------------------------------------------------------------------------------------
# Read Directory
#-------------------------------------------------------------------------------   ---------------------------   
my $excel_directory=getcwd;

my $out_directory = 'xxxout';
opendir(EXCELDIR, $excel_directory) || die ("no excel directory");
my @excelfiles = readdir(EXCELDIR);
closedir(EXCELDIR);

chdir($excel_directory);
   my $LPHname;    # String to hold Local Public Health Name.
   my @sheetarray; # Array to hold the row.
   my $sheetcount; # Array element in the row.
   my $sheetname; # Name of the Excel spreadsheet.
   my $sheettemp;  # Temporary string to hold row for join.
   my $cellnumber;  # Cell number in the row.
   my $cellwanted;  # Cell number in the row.
   my $rowwanted;  # Row number wanted.
   my $county_namecell;  # Cell for county name.
   my $county_namerow;  # Row for county name.
 foreach my $exxfilename (@excelfiles){
 if ($exxfilename =~ /^\.+.*/) { next; }
 my $xls = Spreadsheet::ParseExcel::Simple->read($exxfilename);
 foreach my $sheet ($xls->sheets) {
   $sheetname= $sheet->{sheet}->{Name}; # Sheet Name
   if ($sheetname !~ '2007 Budget') { next; }
   $sheetcount=0;
   $county_namecell=11;
   $county_namerow=1;
#      $cellwanted=4;
   $rowwanted=11;

   while ($sheet->has_data) {
        my @data = $sheet->next_row;
        $sheetcount++;
     if ($sheetcount==$county_namerow){
        $cellnumber=0;
        foreach my $ttcell (@data) {
            $cellnumber++;
            if ($cellnumber != $county_namecell ){next;};
             $sheettemp=$sheetarray[$sheetcount];
#                 $sheetarray[$sheetcount]=join("\t",$sheettemp,$ttcell);
             $LPHname=$ttcell;
        }
     } 

#        if (($sheetcount < ($rowwanted-1)) || 
           ($sheetcount > ($rowwanted+7))){next;}
     if ($sheetcount != $rowwanted){next;};
     $cellnumber=0;
     $sheetarray[$sheetcount]=join("\t",$sheettemp,$LPHname);
     foreach my $ttcell (@data) {
        $cellnumber++;
 #    if ($cellnumber != $cellwanted ){next;};
        $sheettemp=$sheetarray[$sheetcount];
        $sheetarray[$sheetcount]=join("\t",$sheettemp,$ttcell);
     }
   }
}
foreach my $sheetline (@sheetarray){
    print $sheetline,"\n";
}
}
exit
vivi xu
  • 147
  • 1
  • 15
  • [`Spreadsheet::ParseExcel::Simple`](http://search.cpan.org/~tmtm/Spreadsheet-ParseExcel-Simple-1.04/lib/Spreadsheet/ParseExcel/Simple.pm) module is not installed. First install this module. – serenesat Jun 08 '15 at 09:24
  • Before you can program, you must learn how to read. The message says the module can't be located on your computer, not that you did not `use` it in your script. Your script has many problems, but they are not relevant. – Sinan Ünür Jun 08 '15 at 12:01
  • Also, don't you get tired of typing `sheet` everywhere? – Sinan Ünür Jun 08 '15 at 12:02

1 Answers1

1

That error means the module cannot be located. This probably means you need to install the module first.

I'm guessing you've ActivePerl, so what you need to do is:

ppm install Spreadsheet::ParseExcel::Simple
Sobrique
  • 52,974
  • 7
  • 60
  • 101