我有一个perl脚本,它从目录中的许多Excel电子表格中提取行,但由于某些错误消息,它无法正常工作:
我不知道为什么会出现此错误,因为我在脚本中只使用了Spreadsheet::ParseExcel::Simple
两次:
use Spreadsheet::ParseExcel::Simple;
my $xls = Spreadsheet::ParseExcel::Simple->read($exxfilename);
以下是整个代码块供您参考:
# 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
答案 0 :(得分:1)
该错误表示无法找到该模块。这可能意味着您需要先安装模块。
我猜你有ActivePerl,所以你需要做的是:
ppm install Spreadsheet::ParseExcel::Simple