Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^6: Reading Excel file in perl

by Pauler (Initiate)
on Nov 14, 2012 at 03:52 UTC ( #1003740=note: print w/replies, xml ) Need Help??

in reply to Re^5: Reading Excel file in perl
in thread Reading Excel file in perl

Thanks a lott.. It really worked. Thanks for helping. Can u please help me in reading specific row or column value. If i wanna read the column B and its values from excel. Or a certain row. Can u please let me know where i can read these examples or modules.

Replies are listed 'Best First'.
Re^7: Reading Excel file in perl
by marto (Bishop) on Nov 14, 2012 at 10:13 UTC
      I have the below code which reads the column value. But the prb in the code is it prints each column value 3times. Could someone please help in finding the bug. The excel looks like below:
      perl flavors modules class Candidate Name vanilla excel first Nancy strawberry dumper second jimmy lettuce array third roma
      The perl code is as below:
      #use strict; use Spreadsheet::ParseExcel; my $FileName = "/home/dujnne/praice/excel/test.xls"; my $excel = Spreadsheet::ParseExcel::Workbook->Parse($FileName) or die + "Unable to open $FileName\n"; #locate columns in the spreadsheet from which we want to extract data my $found = 0; my ($rowCnt, $colCnt) = (0,0); foreach my $sheet (@{$excel->{Worksheet}}) { printf("Sheet: %s\n", $sheet->{Name}); $sheet->{MaxRow} ||= $sheet->{MinRow}; $rowCnt = $sheet->{MinRow}; foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) { $sheet->{MaxCol} ||= $sheet->{MinCol}; $colCnt = $sheet->{MinCol}; foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { my $cell = $sheet->{Cells}[$row][$colCnt]; if ( lc $cell->{Val} eq "class" ) { $found = 1; print "OKAY: found the column as "class"\n"; print "INFO: searching for all classes \n"; $colCnt++; } if ( $found ) { print $sheet->{Cells}[$row][$colCnt]->{Val}, "\n"; next; } } } $found = 0; }

        Hello Pauler,

        I don’t really understand what this code is trying to do, so I’ll just offer some observations:

        1. The code as given does not compile. This line:

          print "OKAY: found the column as "class"\n";

          needs to be:

          print "OKAY: found the column as \"class\"\n";

          with the inner double-quote characters backslashed.

        2. You should always — yes, always! — begin each script with:

          use strict; use warnings;

          and never comment them out again!

        3. I suspect the script’s main problem is with the next statement on the 6th-last line. This ends the current iteration of the innermost loop, but as it’s the last statement within that loop, it currently does nothing. Perhaps you meant last? Or next LABEL; where LABEL refers back to a previous (i.e., outer) loop? See next and last in Perl documentation.

        Hope that helps,

        Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003740]
[marto]: from experience of this side of the fence, it's all about proving to people that you are ITIL compliant, then the client ignores logical processes anyway :P
[marto]: when you work on the outside, for a client, you can make them aware of the stupids, but they don' t always listen :/
[Corion]: Yeah, you can lead them to water, but it's illegal to drown them...
[Discipulus]: Here my solution marto: create a win fake machine insied AD. do a micro fake partition foreach remote partition you wont to monit. put a web server that acept from data from remote systems and full fake partition as needed. fake partition are Mb. ;=)
[marto]: Discipulus yeah, the nuclear industry love fake machines sitting around on a controlled domain :P
[marto]: changing a typo on a website is often a great deal of paper work :P

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-01-24 10:37 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (203 votes). Check out past polls.