문제

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.

도움이 되었습니까?

해결책

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>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top