Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Parse excel Rows for given column's

by ArifS (Beadle)
on Jul 12, 2016 at 19:07 UTC ( [id://1167641]=perlquestion: print w/replies, xml ) Need Help??

ArifS has asked for the wisdom of the Perl Monks concerning the following question:

This code parse an excel file for 2 rows and prints one cell at a time-
use strict; use warnings; use 5.010; use Spreadsheet::Read qw(ReadData); my $book = ReadData ('excel.xlsx'); my @rows = Spreadsheet::Read::rows($book->[1]); foreach my $i (1 .. scalar @rows) { foreach my $j (1 .. scalar @{$rows[$i-1]}) { say " $i " . " $j " . ($rows[$i-1][$j-1] // ''); } }
Output
1 1 Row1Col1 1 2 Row1Col2 1 3 Row1Col3 1 4 Row1Col4 1 5 Row1Col5 2 1 Row2Col1 2 2 Row2Col2 2 3 Row2Col3 2 4 Row2Col4 2 5 Row2Col5
I am trying to print output for each row's with given column's-
For example, print
Row[i]1st: Row1Col1, Row[i]3rd: Row1Col3
Do the same for other rows... Any suggestion?

====================================================================
Update-
Was able to get the output I was trying for. The following for loop worked-
for my $i (0..1) { print "$sheet->{Cells}[$i][0]{Val}"; $i++; }

Replies are listed 'Best First'.
Re: Parse excel Rows for given column's
by Corion (Patriarch) on Jul 12, 2016 at 19:14 UTC

    Most likely, your course material covers all the techniques you need to employ for solving this task.

    Have you reviewed your course material?

    Have you spoken with your coeds or your tutor about the parts that are unclear to you?

    Maybe, as a first step, you can tell us where you are stuck on solving the problem?

Re: Parse excel Rows for given column's
by haukex (Archbishop) on Jul 12, 2016 at 21:18 UTC

    Hi ArifS,

    Any suggestion?

    Use Data::Dumper to look at @rows, you will see that you have an "array of arrays". How to access data structures like that is explained in perlreftut and perldsc.

    BTW, your current code appears to be 95% copy-and-pasted from this article. That's not necessarily a bad thing but I recommend you additionally show your own efforts in solving the problem.

    Regards,
    -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1167641]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found