machine的blogma2ma.blog.chinaunix.net
machine
全部博文(142)
vim(8)
命令使用(5)
lfs(15)
测试程序(1)
cookbook学习(20)
2011年(8)
2010年(7)
2009年(64)
2008年(63)
xiaoyu98
好儿
jelon521
yviihfw
Bsolar
zzhen201
ghostwwl
llplg
lemontre
jiqing10
nanshanj
分类:
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;}
上一篇:用perl写了一个读excel文档的小程序
下一篇:一张perl 正则的图
登录 注册