emadmahou has asked for the wisdom of the Perl Monks concerning the following question:
# !/usr/bin/perl -w use warnings; use strict; use Data::Dump qw[ pp ]; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; my %DivisionHash; my $inputFile; my $rowCity; my $cellCity; my $prejob; $prejob = shift; $inputFile = shift; $rowCity = shift; $cellCity = shift; open INPUT, "<$inputFile" or die "Unable to open input file: $inputFil +e !!!\nExiting..."; open INPUT2, "<SeedList.L.txt" or die "Unable to open input file: Seed +List.L.txt !!!\nExiting..."; open OUTPUT, ">$prejob.SeedList.L.txt" or die "Unable to create/overwr +ite output file: !!!\nExiting..."; while (<INPUT2>) {print OUTPUT $_;} close INPUT2; while (<INPUT>) { chomp; my $division = uc(trimspaces(substr($_,207-1,20))); # my $DivisionHash = substr($_,207-1,20); if (not exists $DivisionHash{$division}){ $DivisionHash{$division} = $_; # print STDOUT $DivisionHash{$division}; }# exit; } close INPUT; my $filename = "\\Aldi_Production_Emad.xlsx"; # Parse excel file my $parser = Spreadsheet::ParseXLSX->new; my $workbook = $parser->parse("$filename"); if ( !defined $workbook ) { die $parser->error(), ".\n"; } # Get cell value from excel sheet1 row 1 column 2 my $worksheet = $workbook->worksheet(0); my $cell = $worksheet->get_cell($rowCity,$cellCity); # Print the cell value when not blank if ( defined $cell and $cell->value() ne "") { my $value = $cell->value(); $value = uc(trimspaces($value)); # print STDOUT "this is value: $value"; # exit; # if($DivisionHash eq $value){ # print OUTPUT $_ . "\n"; # } if(exists ($DivisionHash{$value})) { # print STDOUT $DivisionHash{$value}; # exit; # $_ = $DivisionHash{$value}; print OUTPUT $DivisionHash{$value} . "\n"; } else { print STDERR "Value $value Doesn't exist \n"; exit; } } close OUTPUT; sub trimspaces { my @argsarray = @_; $argsarray[0] =~ s/^\s+//; $argsarray[0] =~ s/\s+$//; return $argsarray[0]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: loop through xlsx and get specific column cell values
by Athanasius (Archbishop) on Apr 17, 2016 at 03:17 UTC | |
by ww (Archbishop) on Apr 17, 2016 at 12:28 UTC | |
|
Re: loop through xlsx and get specific column cell values
by ww (Archbishop) on Apr 17, 2016 at 03:08 UTC |