#!/usr/bin/perl
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my @files = ("e:\\perl\\test.xlsx");
my $value = 0;
my %hash = {
"北京" => (),
"天津" => (),
};
foreach my $file (@files){
my $book = $Excel->Workbooks->Open( $file );
foreach my $Sheet (in $book->{Worksheets})
{
my $sheetName = $Sheet->{Name};
print "$sheetName\n";
my $minRow = 1;
my $maxRow = $Sheet->UsedRange->Rows->Count;
my $minCol = 2;
my $maxCol = $Sheet->UsedRange->Columns->Count;
foreach my $row ( $minRow .. $maxRow ){
my $cell_value = $Sheet->Cells($row,1)->{Value};
next unless defined $cell_value;
if(exists $hash{$cell_value}){
foreach my $col ( $minCol .. $maxCol ){
my $value = $Sheet->Cells($row,$col)->{Value};
next unless defined $value;
push $hash{$cell_value}, $value;
}
}
}
}
$book->Close();
}
foreach my $key (keys %hash){
print "$key $hash{$key}\n";
}
$Excel->Quit();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)