我有一个将xlsx文件转换为csv文件的脚本。但是我怎样才能将特定(命名)工作表从xlsx工作簿(带有多个工作表)转换为csv文件。
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::BasicRead;
use Excel::Writer::XLSX;
use Spreadsheet::ParseExcel;
my $xlsx = ("c:\\acb.xlsx"),,1;
my $csv = ("c:\\acb.csv"),,1;
if (-e $xlsx) {
my $ss2 = new Spreadsheet::BasicRead($xlsx) or die;
my $name2 = '';
my $row2 = 0;
open(FILE2, ">$csv") or die ;
binmode(FILE2, ":utf8"); # Wide character in print warnings
while (my $data2 = $ss2->getNextRow()){
$row2++;
$name2 = join(',', @$data2);
print FILE2 $name2."\n" if ($name2 ne "");
}
close FILE2;
}
答案 0 :(得分:0)
在$ss2->setCurrentSheetNum(num)
和binmode
之间添加while
。这应该适合你。
HTH!
TheJester1977