Rookie: Accessing specific element of excel->range array

Discussion in 'Perl Misc' started by sdfgsd, Nov 3, 2003.

  1. sdfgsd

    sdfgsd Guest

    Hello All,

    Here's the code. As you can see, I've put a range of excel values into the
    array $cells. Before proceeding, I need to access one or two specific values
    that remain constant in their location within the array.

    My problem: I can't seem to understand how to access a specific
    value/element in the array. See comment in the code. Thanks for any help.

    ========================================

    my $cells = $worksheet->Range("A1:D22")->{'Value'};

    print "The content of this cell is: ", $@cells[0][2];
    ^^^^^^^^^^^
    # According to the books and perldoc, this should work, but it doesn't?

    foreach my $row (@$cells) {
    foreach my $rec (@$row) {
    $rec =~ s/^\s+//;
    $rec =~ s/\s+$//;
    $rec =~ s/[^a-zA-Z0-9 .-]//g;
    print "$rec\n";
    }
    }
    sdfgsd, Nov 3, 2003
    #1
    1. Advertising

  2. sdfgsd

    sdfgsd Guest

    "sdfgsd" <> wrote in message
    news:GIvpb.113798$...
    > Hello All,
    >
    > Here's the code. As you can see, I've put a range of excel values into the
    > array $cells. Before proceeding, I need to access one or two specific

    values
    > that remain constant in their location within the array.
    >
    > My problem: I can't seem to understand how to access a specific
    > value/element in the array. See comment in the code. Thanks for any help.
    >
    > ========================================
    >
    > my $cells = $worksheet->Range("A1:D22")->{'Value'};
    >
    > print "The content of this cell is: ", $@cells[0][2];
    > ^^^^^^^^^^^
    > # According to the books and perldoc, this should work, but it doesn't?

    ==========================================

    I solved this by reassigning $cells to another array. Not sure if this is
    the most elegant way, but it works...

    my $cells = $worksheet->Range("A1:D22")->{'Value'};
    my @ArrCell = @$cells;

    print "The content of this cell is: ", $ArrCell[0][1];

    > foreach my $row (@$cells) {
    > foreach my $rec (@$row) {
    > $rec =~ s/^\s+//;
    > $rec =~ s/\s+$//;
    > $rec =~ s/[^a-zA-Z0-9 .-]//g;
    > print "$rec\n";
    > }
    > }
    sdfgsd, Nov 3, 2003
    #2
    1. Advertising

  3. On Mon, 3 Nov 2003, sdfgsd wrote:

    >my $cells = $worksheet->Range("A1:D22")->{'Value'};
    >
    >print "The content of this cell is: ", $@cells[0][2];


    You want to do

    $cells->[0][2]

    --
    Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
    "And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
    years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
    Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
    Jeff 'japhy' Pinyan, Nov 3, 2003
    #3
  4. sdfgsd

    sdfgsd Guest

    "Jeff 'japhy' Pinyan" <> wrote in message
    news:p...
    > On Mon, 3 Nov 2003, sdfgsd wrote:
    >
    > >my $cells = $worksheet->Range("A1:D22")->{'Value'};
    > >
    > >print "The content of this cell is: ", $@cells[0][2];

    >
    > You want to do
    >
    > $cells->[0][2]


    It works. Thanks!
    sdfgsd, Nov 4, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    733
  2. zxo102
    Replies:
    3
    Views:
    3,257
    Stuart Corrie
    Aug 9, 2005
  3. HANM
    Replies:
    2
    Views:
    706
    Joseph Kesselman
    Jan 29, 2008
  4. mazdotnet
    Replies:
    2
    Views:
    393
    Alexey Smirnov
    Oct 2, 2009
  5. nmvega
    Replies:
    1
    Views:
    164
Loading...

Share This Page