Hello snehit.ar,

Why don't you use the method rows from the same module Spreadsheet::Read, which actually does exactly what you want. See example bellow based on the data that you provide us.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Spreadsheet::Read; my $book = ReadData("test.xlsx"); my $sheet = $book->[1]; # first data sheet my @rows = Spreadsheet::Read::rows ($book->[1]); print Dumper \@rows; __END__ $ perl test.pl $VAR1 = [ [ 'AA1', 'BB1' ], [ undef, undef ], [ 111, 101 ], [ 222, 202 ], [ 333, 303 ], [ 444, 404 ], [ 555, 505 ], [ 666, 606 ], [ 777, 707 ], [ 888, 808 ], [ 999, 909 ] ];

Update: Or if you do not want to retrieve and iterate over the rows to get the values that you want. You can get them directly like the example bellow:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Spreadsheet::Read; my $book = ReadData("test.xlsx"); my $sheet = $book->[1]; # first data sheet my @column = $sheet->{cell}[2]; # 2nd column, unformatted print Dumper \@column; __END__ $ perl test.pl $VAR1 = [ [ undef, 'BB1', undef, 101, 202, 303, 404, 505, 606, 707, 808, 909 ] ];

Update2: Alternative way of printing the Array of Arrays (@column).

use feature 'say'; foreach my $row (@column) { for (@$row) { say $_ if (defined) } }

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Read excel column and compare with array by thanos1983
in thread Read excel column and compare with array by snehit.ar

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.