2013-03-18 29 views
1

我可以通過應用程序的.Selection屬性獲取區域。如何獲取Excel的COM接口選擇的行數和列數?

(我使用python訪問Excel的COM接口)

我想知道有多少行和列的用戶選擇,例如

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 ?) 

我期待在MSDN的Range interface,但該物業似乎並沒有對這個問題有所幫助。

回答

0

從VBA,你可以做這樣的事情:

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

隨着A1:選擇G8,這將返回

8 
7 
1 
1 

那是很容易地轉換到Python>

+0

感謝,'選擇.Rows.Count'和'Selection.Columns.Count'起作用。 – thkang 2013-03-18 09:44:50

相關問題