Hi all, I have a spreadsheet with around 47 columns and n number of rows. I only need certain columns for further processes in my script.


Ideally, I would need the values from first , third and the columns from 13 -49. I would like to print these in comma separated format like this/assign the values to a variable($id, $snum, @rs)/or in a hash :
1, 23,45, 454,54,45,656,56,565,65,.... 2,343,4545, 5656,56,6767,67,6,767,6,76,767,... 3,454, 56546,4545,6,45,64,5,45,4,5,4,54,54,5,4,...
#!/software/bin/perl BEGIN { unshift @INC, '/nfs/users/nfs_d/dmb/perl/lib' ; unshift @INC, '/nfs/users/nfs_d/dmb/perl/lib2' ; } use strict; #use warnings ; use File::Basename ; use Algorithm::Permute ; use Spreadsheet::ParseExcel; use Getopt::Long; my($excel_file, $outputdir); &GetOptions("if=s" =>\$excel_file, "od=s" =>\$outputdir, ); my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->Parse($excel_file) || die "Cannot parse the fi +le $!\n" ; for my $worksheet ( $workbook->worksheets() ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( 1.. $row_max ) { my @required_col = (0,2,13..47); for my $col(@required_col){ my $cell = $worksheet->get_cell($row, $col ); next unless $cell; print ($row, $col),"\n"; print $cell->value(),"\n"; # print "Unformatted = ", $cell->unformatted(), "\n"; print "\n"; } } }
I would actually want them to either be able to get the values of those columns stored in a variable or able to print to a file in a csv format. Advance thanks for all the suggestions!

In reply to 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.