文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用perl分析并比较excel表格内容的小脚本

使用perl分析并比较excel表格内容的小脚本

时间:2009-05-25  来源:machine

没事随便写的,呵呵  

#! perl -w

#

#

use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode;

my ($source_file,$filter_file) = @ARGV;
open FILE,">out.txt" or die "open target file error!";
die "usage: filter.pl source_file filter_file" unless $source_file;
die "usage: filter.pl source_file filter_file" unless $filter_file;
my $parser = Spreadsheet::ParseExcel->new();
my $oFmtJ = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => 'CP936' );
my $workbook_s = $parser->Parse($source_file,$oFmtJ) or die "can't parse source file: $!";
my $worksheet_s = ($workbook_s->worksheets())[0] or die "can't open sheets: $!";
my $workbook_f = $parser->Parse($filter_file,$oFmtJ) or die "can't parse this file: $!";
my $worksheet_f = ($workbook_f->worksheets())[0] or die "can't open sheets: $!";
my ( $srow_min, $srow_max ) = $worksheet_s->row_range();
my ( $scol_min, $scol_max ) = $worksheet_s->col_range();
my ( $frow_min, $frow_max ) = $worksheet_f->row_range();
my ( $fcol_min, $fcol_max ) = $worksheet_f->col_range();
my $line;
for my $row ($srow_min .. $srow_max ) {
    my $cell = $worksheet_s->get_cell( $row, 2 );
         if (find_no($cell->value())){
              $line='';
            for my $col ($scol_min .. $scol_max){
               $line .= ($worksheet_s->get_cell( $row, $col )->value()) . '|';
            }
            $line =~ s/\|$/\n/;
           #print $line;

           print FILE $line;
         }
}

sub find_no {
   my ($number)=shift @_;
   for my $row ($frow_min .. $frow_max ) {
        my $cell = $worksheet_f->get_cell( $row, 0 );
        #print $number . ":" .($cell->value()) ."\n";

      if($number eq $cell->value()){
        return 1;
      }
   }
   return 0;
}

相关阅读 更多 +
排行榜 更多 +
宝宝情商养成宝宝巴士

宝宝情商养成宝宝巴士

休闲益智 下载
燥热手机版

燥热手机版

飞行射击 下载
巨人狙击手安卓版

巨人狙击手安卓版

飞行射击 下载