如何select与Excel中特定variables匹配的特定行?

我得到了一个存储在数组中的variables列表。 我知道如何select特定的列和行,但我只想select与数组中的variables匹配的特定行(假设所有variables都是唯一的,只会出现在Excel中)。 这是可能的吗?怎么做?

Excel中:

Name Code Age John 0123 18 ean 1234 19 

我的代码现在:

 use strict; use warnings; use Spreadsheet::ParseXLSX; @name = ("john", "tommy", "ming", "ean"); ##Loop through the array and search in excel## foreach my $test (@name) { my $parser = Spreadsheet::ParseXLSX->new(); my $workbook = $parser->parse('C:\namelist.xlsx'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } for my $worksheet ( $workbook->worksheets('Name List') ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { **Any Idea what should I do here to get expected result?** } } } } 

预期的结果:当循环访问数组@name ,它将在excel中search,如果像John这样的variables匹配,它将检索该行的所有数据并将其存储在variables中。 例如。 $code = 01234;$Age=18;

任何相关的post / info / ans分享,因为我找不到一个。 谢谢!

尝试在Perl中使用下面的代码:

 use strict; use warnings; use Spreadsheet::ParseXLSX; my $parser = Spreadsheet::ParseXLSX->new(); my $workbook = $parser->parse('C:\namelist.xlsx'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my @name = ("john", "tommy", "ming", "ean"); for my $worksheet ( $workbook->worksheets('Name List') ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); next unless $cell; foreach my $result (@name) { my $string = $cell->value(); if($result =~ m/$string/i) { my $codeCell = $worksheet->get_cell($row,1); my $ageCell = $worksheet->get_cell($row,2); print "Name : $string\t"; if(defined $codeCell and $codeCell->value() ne "") { my $code = $codeCell->value(); print "Code : $code\t"; } if(defined $ageCell and $ageCell->value() ne "") { my $age = $ageCell->value(); print "Age : $age\n"; } } } } } }