Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Problem enumerating Worksheets with Spreadsheet::ParseExcel

by mikeB (Friar)
on Dec 17, 2001 at 22:01 UTC ( #132586=perlquestion: print w/replies, xml ) Need Help??

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

The code below has two foreach loop headers. The one commented out works (i.e., loop on index numbers). The one not commented out does not work, but seems like it should. It runs through the loop the proper number of times, but the ->{Name} element is undefined.

Any thoughts?

#!/usr/bin/perl -w use strict; use Data::Dumper; use Spreadsheet::ParseExcel; my $excel = new Spreadsheet::ParseExcel or die; my $book = $excel->Parse($ARGV[0]) or die; my $sheet; foreach $sheet (@{$book->{Worksheet}}) { #foreach (0 .. $book->{SheetCount}) { # $sheet = $book->{Worksheet}[$_]; print $sheet->{Name},"\n"; }

Replies are listed 'Best First'.
Re: Problem enumerating Worksheets with Spreadsheet::ParseExcel
by jmcnamara (Monsignor) on Dec 17, 2001 at 22:34 UTC

    I get the opposite results. The uncommented loop works and the commented loop gives a warning.

    The warning occurs because SheetCount is the index of the last worksheets +1. So I guess this is what you want (although I prefer the other method):

    foreach (0 .. $book->{SheetCount} -1) { $sheet = $book->{Worksheet}[$_]; print $sheet->{Name},"\n"; }


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-01-17 05:13 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (51 votes). Check out past polls.