在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#!/usr/bin/perl use strict; use Spreadsheet::ParseExcel; my $oExcel = new Spreadsheet::ParseExcel; die "Usage : \n\tperl $0 <xls> > xls.txt\n\n" unless @ARGV; my $oBook = $oExcel->Parse($ARGV[0]); my($iR, $iC, $oWkS, $oWkC); for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++){ $oWkS = $oBook->{Worksheet}[$iSheet]; for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) { for(my $iC = $oWkS->{MinCol} ; defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; $iC++) { $oWkC = $oWkS->{Cells}[$iR][$iC]; print $oWkC->Value,"\t" if($oWkC); } print "\n"; } } 输入为xls格式,集群下可用。 txt2excel.pl #!/usr/bin/perl use strict; use Encode qw(decode); use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("$ARGV[0].xls"); my $worksheet = $workbook->add_worksheet(); # Row and column are zero indexed my $row = 0; open IN,$ARGV[0] or die $!; while(<IN>){ chomp;my @s = split; my $col = 0; foreach my $token(@s){ $worksheet->write_string($row,$col,decode('gb2312',$token)); $col++; } $row++; } close IN; |
请发表评论