perl - How to select the specific row that matched a specific variable in excel? -
perl - How to select the specific row that matched a specific variable in excel? -
i got list of variables stored in array. know how select specific columns , rows want select specific row matched variables in array (assume variables unique, appear in excel once). possible , how can done?
excel:
name code age john 0123 18 ean 1234 19
my code now:
use strict; utilize warnings; utilize spreadsheet::parsexlsx; @name = ("john", "tommy", "ming", "ean"); ##loop through array , search in excel## foreach $test (@name) { $parser = spreadsheet::parsexlsx->new(); $workbook = $parser->parse('c:\namelist.xlsx'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } $worksheet ( $workbook->worksheets('name list') ) { ( $row_min, $row_max ) = $worksheet->row_range(); ( $col_min, $col_max ) = $worksheet->col_range(); $row ( $row_min .. $row_max ) { $col ( $col_min .. $col_max ) { **any thought should here expected result?** } } } }
expected result: while looping through array @name
, search in excel, if variable john
matched, retrieve info of row , store in variables. eg. $code = 01234;
, $age=18;
any related post/info/ans share can't found one. thanks!
try using below code in perl :
use strict; utilize warnings; utilize spreadsheet::parsexlsx; $parser = spreadsheet::parsexlsx->new(); $workbook = $parser->parse('c:\namelist.xlsx'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } @name = ("john", "tommy", "ming", "ean"); $worksheet ( $workbook->worksheets('name list') ) { ( $row_min, $row_max ) = $worksheet->row_range(); ( $col_min, $col_max ) = $worksheet->col_range(); $row ( $row_min .. $row_max ) { $col ( $col_min .. $col_max ) { $cell = $worksheet->get_cell( $row, $col ); next unless $cell; foreach $result (@name) { $string = $cell->value(); if($result =~ m/$string/i) { $codecell = $worksheet->get_cell($row,1); $agecell = $worksheet->get_cell($row,2); print "name : $string\t"; if(defined $codecell , $codecell->value() ne "") { $code = $codecell->value(); print "code : $code\t"; } if(defined $agecell , $agecell->value() ne "") { $age = $agecell->value(); print "age : $age\n"; } } } } } }
excel perl
Comments
Post a Comment