Rookie: Accessing specific element of excel->range array

S

sdfgsd

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";
}
}
 
S

sdfgsd

sdfgsd said:
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";
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top