pythonexcelcompywin32pyxll

How can I get number of rows and columns selected by excel COM interface?


I can get area selected by application's .Selection property.

(I'm using python to access excel com interface)

I want to know how many rows and columns user have selected, for instance

input:
    user has selected A1:G8
output:
    the selected range starts from Column 1 (by selection.Column)
    the selected range starts from Row 1 (by selection.Column)
    the selected range is spanning 7 rows (by ?)
    the selected range is spanning 8 columns (by ?)

I'm looking at MSDN's Range interface, but the property's doesn't seems to be helpful for this problem.


Solution

  • From VBA, you could do something like this:

    Debug.Print Selection.Rows.Count
    Debug.Print Selection.Columns.Count
    Debug.Print Selection.Row
    Debug.Print Selection.Column
    

    With A1:G8 selected, this returns

    8 
    7 
    1 
    1 
    

    Is that easily translated to Python>