如何在C#中获取Excel 2003单元格的X和Y屏幕
本文关键字:单元格 屏幕 2003 Excel 获取 | 更新日期: 2023-09-27 17:58:46
在编写C#Excel 2003加载项时,如何在Excel 2003中找到单元格的绝对位置(例如相对于屏幕的位置)。
"范围"(Range)的"上"(Top)和"左"(Left)属性(如ActiveCell)似乎给出了相对于左上角单元格的X和Y。窗口。左和上给出了窗口的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