for my $row ( 0 .. 0 ) { @value = map { my $cell = $worksheet->get_cell($row, $_); $cell ? $cell->value() : ''; } @required_col; #### #!/software/bin/perl BEGIN { unshift @INC, '/nfs/users/nfs_d/dmb/perl/lib' ; unshift @INC, '/nfs/users/nfs_d/dmb/perl/lib2' ; unshift @INC, '/nfs/users/nfs_a/aj6/CGP/perl_stuffs/lib/lib/site_perl/5.8.8/'; } use File::Basename ; use Algorithm::Permute ; use Spreadsheet::ParseExcel; use Getopt::Long; use Text::CSV; use strict; use warnings ; my @required_col = (0,1,2,13..47); GetOptions( "if=s" => \my $excel_file, "od=s" => \my $outputdir, ); my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->Parse($excel_file); if ( !defined $workbook ) { die $parser->error(), ".\n"; } my $newfile = $excel_file . ".csv"; my $csv = Text::CSV->new ( { eol => "\n" } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, '>', $newfile or die "Can't open $newfile: $!"; my @worksheets = $workbook->worksheets(); warn "More than 1 worksheet found\n" if @worksheets > 1; # Only work with first page. my $worksheet = $worksheets[0]; my @hea = $worksheet->{Header}; print @hea; my ( $row_min, $row_max ) = $worksheet->row_range(); my @value; ##to get the headers of the excel file; for my $row ( 0 .. 0 ) { @value = map { my $cell = $worksheet->get_cell($row, $_); $cell ? $cell->value() : ''; } @required_col; } # Skip header row my @data; for my $row ( 1 .. $row_max ) { @data = map { my $cell = $worksheet->get_cell($row, $_); $cell ? $cell->value() : ''; } @required_col; &changeformat(\@value,\@data); } sub changeformat{ my ($header,$data) = @_; my(%hash1,%hash2); my $plex1 = shift @$header; #since passed through the loop again and again, shifts the first element every time it passes through the loop $hash2{$plex1} = \@$header; my $plex = shift @$data; my $sangerid = shift @$data; my $supplierid = shift @$data; $hash1{$supplierid} = \@$data; foreach my $key (keys %hash1){ foreach my $k(keys %hash2){ for(my$i = 0;$i<=scalar(@$data);$i++){ # print "$key,$hash1{$key}[$i], $plex,$hash2{$k}[$i]\n" if ($hash2{$k}[$i] and $key); } } } }