如何获得在C#中的Excel 2003单元的屏幕X和Y [英] How to get screen X and Y of an Excel 2003 cell in C#
问题描述
我如何才能找到在Excel 2003中的单元格的绝对位置(例如相对于屏幕[S])编写C#Excel 2003中加载项时。
How can I find the absolute position of a cell in Excel 2003 (e.g. relative to the screen[s]) when writing a C# Excel 2003 Add-in.
的顶部和一个范围(例如ActiveCell)的左属性似乎给X和Y相对于顶部左手细胞。 Window.Left和Top给窗口的X和Y,但我不能找到一个办法让在中间位的大小(包括工具栏和这样的)。
The Top and Left properties of a Range (such as ActiveCell) seem to give the X and Y relative to the top-left hand cell. Window.Left and Top give the X and Y of the window, but I can't find a way to get the size of the bit in the middle (consisting of Toolbars and such).
这里的目的是为了显示涉及选定单元格的WPF的形式,并位于靠近它。
The aim here is to display a WPF form that relates to the selected cell, and is positioned adjacent to it.
我觉得像我丢失基本的东西在这里。 !任何帮助非常感谢
I feel like I'm missing something basic here. Any help greatly appreciated!
推荐答案
下面的链接有一些VBA代码,这可能是能够指出你在正确的方向: 形式定位。
The following link has some VBA code, which might be able to point you in the right direction: Form Positioner .
这是更多地参与比我想象的,但如果你需要找到一些Excel的命令栏的高度,以他们为榜样下面的VBA代码可能会有所帮助:
It's more involved than I would have thought, but if you need to find the height of some of the Excel commandbars, the following VBA code in their example might help:
'
' we'll assume that the application's caption bar and the formula
' bar are the same height as the menu bar. If we can't figure that out, use 26 as a default.
'
If Application.CommandBars.ActiveMenuBar.Visible = True Then
DefaultCmdBarHeight = Application.CommandBars.ActiveMenuBar.Height
Else
DefaultCmdBarHeight = cDefaultCmdBarHeight
End If
'
' We have to have a compenstating factor for command bars. Load an array
' with the heights of visible command bars. The index into the array is
' the RowIndex of the command bar, so we won't "double dip" if two or more
' command bars occupy the same row.
'
For Each CmdBar In Application.CommandBars
With CmdBar
If (.Visible = True) And (.Position = msoBarTop) Or (.Position = msoBarMenuBar) Then
If .RowIndex > 0 Then
VCmdArr(.RowIndex) = .Height
End If
End If
If (.Visible = True) And (.Position = msoBarLeft) Then
If .RowIndex > 0 Then
HCmdArr(.RowIndex) = .Width
End If
End If
End With
Next CmdBar
这篇关于如何获得在C#中的Excel 2003单元的屏幕X和Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!