在编译以下代码时,我得到了两个错误:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $xlsparser = Spreadsheet::ParseExcel->new();
my $xlsbook = $parser->parse('xsl_test.xls');
my $xls = $xls->worksheet(0);
my ( $row_first, $row_last ) = $xls->row_range();
my ( $col_first, $col_last ) = $xls->col_range();
my $csv = '';
for my $row ( $row_first .. $row_last ) { #Step through each row
for my $col ( $col_first .. $col_last ) { #Step through each column
my $cell = $xls->get_cell( $row, $col ); #Get the current cell
next unless $cell;
$csv .= $cell->unformatted(); #Get the cell's raw data -- no border colors or anything like that
if ( $col == $col_last ) {
$csv .= "\n"; #Make a new line at the end of the row
} else {
$csv .= ",";
}
}
}错误:
global symbol "$parser" requires explicit package name at line 8
global symbol "$xls" requires explicit package name at line 9我从http://www.ehow.com/how_7352636_convert-xls-csv-perl.html获得上述代码,并使用以下命令安装excel模块:cpan Spreadsheet::ParseExcel Spreadsheet::XLSX Spreadsheet::Read
是什么导致了这个错误?
发布于 2014-10-31 10:41:29
这些错误意味着您正在使用strict,但是您没有用my声明一些变量。例如,您声明了$xmlprser,但随后尝试使用未声明的$parser。您复制的代码有错误。
获取代码的更好地方是源代码本身:Spreadsheet::ParseExcel
尝试:
my $parser = Spreadsheet::ParseExcel->new();
my $xlsbook = $parser->parse('xsl_test.xls');
my $xls = $xlsbook->worksheet(0);https://stackoverflow.com/questions/26666710
复制相似问题