1

我可以获取应用程序.Selection属性选择的区域。

(我正在使用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,但该属性似乎对这个问题没有帮助。

4

1 回答 1

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>

于 2013-03-18T09:17:14.030 回答