in reply to Re: Read excel column and compare with array
in thread Read excel column and compare with array

hello BR, Thanks for the replay. But it gives all excel rows,column. I want to display only column(BB1) and store in array .
$VAR1 = [ [ 101 ], [ 202 ], [ 303 ], [ 404 ], [ 505 ], [ ..... ];

Replies are listed 'Best First'.
Re^3: Read excel column and compare with array
by hippo (Archbishop) on Jul 17, 2017 at 09:36 UTC

    That's pretty trivial with map:

    #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @rows = ( [ 'AA1', 'BB1' ], [ undef, undef ], [ 111, 101 ], [ 222, 202 ], [ 333, 303 ], [ 444, 404 ], [ 555, 505 ], [ 666, 606 ], [ 777, 707 ], [ 888, 808 ], [ 999, 909 ] ); my @bb1 = map { $_->[1] } @rows; print Dumper \@bb1;
      Thanks for help..
Re^3: Read excel column and compare with array
by thanos1983 (Parson) on Jul 17, 2017 at 09:38 UTC

    Hello again snehit.ar,

    Well you can iterate over the array of arrays and simply choose to keep or print the second value of the array (I am not going to create the foreach loop for you). A minimum amount of effort is required, read more here perldsc/ARRAYS OF ARRAYS. Regarding the column straight data read my update.

    Minor note, my username on the forum is thanos1983, BR stands for (Best Regards) :)

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Hi thanos1983, I am sorry for your name. I have tired this ...
      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Spreadsheet::Read; use Spreadsheet::XLSX; use Text::Iconv; my $converter = Text::Iconv -> new ("utf-8", "windows-1251"); my $excel = Spreadsheet::XLSX -> new ('C:/SLB/Dashboard/DCSS_Applicati +ons.xlsx', $converter); my @DCSS_ss; foreach my $sheet (@{$excel -> {Worksheet}}) { printf("Sheet: %s\n", $sheet->{Name}); $sheet -> {MaxRow} ||= $sheet -> {MinRow}; foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) { $sheet -> {MaxCol} ||= $sheet -> {MinCol}; my $cell = $sheet -> {Cells} [$row] [2]; s/^\s+|\s+$//g for $cell->{Val}; if ($cell) { push @DCSS_ss, { SSRID =>$cell -> {Val} }; } } } print Dumper \@DCSS_ss;
      TY

        Hello snehit.ar,

        Are you getting an error? Is it not working? What is the problem? (I have not run your updated code).

        Update: I just found that you are copying pasting the example given from the module Spreadsheet::XLSX. You can not mix modules and expect them to work. The methods do not apply on both modes. Decide which module you want to use and create your solution.

        Hint: read again module Spreadsheet::Read/sheets and find the line my $sheets = $book->sheets; I think this is what you are looking for.

        BR, Thanos1983.

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