如何在C#中获取Excel 2003单元格的屏幕X和Y

在编写C#Excel 2003加载项时,如何在Excel 2003中找到单元格的绝对位置(例如,相对于屏幕[s])。

范围的Top和Left属性(例如ActiveCell)似乎相对于左上角单元格给出X和Y. Window.Left和Top给出了窗口的X和Y,但我找不到一种方法来获得中间位的大小(由工具栏等组成)。

这里的目的是显示与所选单元格相关的WPF表格,并且与其相邻。

我觉得我在这里遗漏了一些基本的东西。 任何帮助非常感谢!

以下链接包含一些VBA代码,可能会指向正确的方向: Form Positioner 。

它比我想象的更复杂,但如果你需要找到一些Excel命令栏的高度,他们示例中的以下VBA代码可能会有所帮助:

 ' ' 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