Chinaunix首页 | 论坛 | 博客
  • 博客访问: 470032
  • 博文数量: 142
  • 博客积分: 4126
  • 博客等级: 上校
  • 技术积分: 1545
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-22 10:03
文章分类

全部博文(142)

文章存档

2011年(8)

2010年(7)

2009年(64)

2008年(63)

我的朋友

分类:

2009-05-25 14:11:24

没事随便写的,呵呵
 

#! 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;
}


阅读(1455) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~