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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |