如何将.xls
转换为.csv
in 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行。
一些很好的参考http://www.ehow.com/how_7352636_convert-xls-csv-perl.html http://vinayhacks.blogspot.in/2010/04/converting-xls-to-csv- on-linux.html –
请参阅我的更新问题 – Ram
[将.xls文件转换为.csv文件?](http://stackoverflow.com/questions/21772377/converting-xls-file-to-csv-file) –