Hi thanks,! Is there any way to return the headers(or the column descriptors) of the Excel file using Spreadsheet::ParseExcel? At the moment am getting them by,
for my $row ( 0 .. 0 ) { @value = map { my $cell = $worksheet->get_cell($row, $_); $cell ? $cell->value() : ''; } @required_col;
But, I couldn't pass the @value array to another subroutine; which takes an array of data as mentioned before.

I need both the arrays in the next subroutine.
#!/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_p +erl/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 ($hash +2{$k}[$i] and $key); } } } }

Any fix /suggestions how to pass it?

thanks a ton

In reply to Re^2: Spreadsheet::ParseExcel assigning the column by Anonymous Monk
in thread Spreadsheet::ParseExcel assigning the column by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.