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