Home » excel » perl – Position of Range-Object in Excel

perl – Position of Range-Object in Excel

Posted by: admin May 14, 2020 Leave a comment


I am trying to figure out how to get the position of a selected Range in an Excel(2007)-Worksheet. Is there something similar to $self->{EXCEL}->ActiveCell->Row for Cells (self->{EXCEL} being an Excel-Object)?

I tried ->Selection->Range, ->ActiveSheet->Range, and as a workaround ->Range->Row, ->Range->Rows both with an Excel- and a Worksheet-Object with no success.

The most fancy output being two Cell-Objects, one for the start-address, the other one end-address.

Thanks for any helpful hints!

=== Update ===

I now use successfully the command $self->{EXCEL}->Selection->Address(); to retrieve the address of the selected range. By default I get the address in “A1”-format ($E$1:$G$14). Using ->Address("ToReferenceStyle:=xlR1C1") however does not return the address in “R1C1”-format as I would have expected…

Faulty command? Ignorant Excel? Thanky again on any helpful hint!

How to&Answers:

How about ->Selection->Address? I’m not sure on the format, but the address property of the selection (range object) will give you the address of the range for example. $A$1:$B$7. You would be able to parse the start and end by splitting the string on the colon.

To address your new questions… I’m not even sure if what you’re using, but the third parameter of the address method is ReferenceStyle not ToReferenceStyle. So I would try either ->Address(ReferenceStyle:=xlR1C1) or ->Address(,,xlR1C1)