Как получить экран X и Y ячейки Excel 2003 в C # - PullRequest
0 голосов
/ 08 июня 2011

Как найти абсолютную позицию ячейки в Excel 2003 (например, относительно экрана [ов]) при написании надстройки C # Excel 2003.

Свойства Top и Left в Range (например, ActiveCell), похоже, дают X и Y относительно верхней левой ячейки.Window.Left и Top дают X и Y окна, но я не могу найти способ получить размер бита посередине (состоящий из панелей инструментов и тому подобное).

Цель здесьчтобы отобразить форму WPF, которая относится к выбранной ячейке и расположена рядом с ней.

Мне кажется, что я здесь упускаю что-то базовое.Любая помощь с благодарностью!

1 Ответ

0 голосов
/ 09 июня 2011

Следующая ссылка содержит некоторый код VBA, который может указать вам правильное направление: Позиционер форм .

Это более сложный процесс, чем я мог подумать, но если вынужно найти высоту некоторых командных команд 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
...