我的perl脚本将.xls转换为.csv
use Spreadsheet::ParseExcel;
my $xlsparser = Spreadsheet::ParseExcel->new();
my $xlsbook = $xlsparser->parse('/home/Admin/Downloads/abc.xls');
my $xls = $xlsbook->worksheet(0);
my ( $row_first, $row_last ) = $xls->row_range();
my ( $col_first, $col_last ) = $xls->col_range();
my $csv = '/home/Admin/Downloads/ram.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";
} else {
$csv .= ",";
}
}
}
open(my$FH ,'>',"$csv") or die "oops!";
while (my$line = <$xlsbook>){
print $FH $line;
}
糟糕!在csv.pl第23行。
投掷错误。我的代码有什么问题?请在我的代码中找到错误。 提前谢谢。
答案 0 :(得分:0)
你有一个错字:
open(my $FH ,'>',"$csv") or die "oops!";
使用严格和警告,并在编译期间收到警告。
use strict;
use warnings;
你有拼写错误:
open(my $FH ,'>',$csv) or die "oops!";
while (my$line = <$FH>){
此致