C# 如何设置Excel窗口的大小?

C# 如何设置Excel窗口的大小?,c#,wpf,excel,office-interop,excel-interop,C#,Wpf,Excel,Office Interop,Excel Interop,我有一个wpf窗口,应该在Excel窗口旁边打开。Excel是用Interop.Excel打开和处理的。 在我的窗口中,我有一个方法,可以设置excel窗口的大小 private void SetLayout() { Top = 0; Left = 0; Height = SystemParameters.WorkArea.Height; ((ConfiguratorWindowVie

我有一个wpf窗口,应该在Excel窗口旁边打开。Excel是用Interop.Excel打开和处理的。 在我的窗口中,我有一个方法,可以设置excel窗口的大小

private void SetLayout()
        {
            Top = 0;
            Left = 0;
            Height = SystemParameters.WorkArea.Height;
            ((ConfiguratorWindowViewModel) DataContext).Manager.App.Height =
                SystemParameters.WorkArea.Height;
            ((ConfiguratorWindowViewModel) DataContext).Manager.App.Left = Width;
            ((ConfiguratorWindowViewModel) DataContext).Manager.App.Width = SystemParameters.WorkArea.Width - Width;
        }
在我的Viewmodel中,我有一个管理器,它返回打开的Excel应用程序(Office.Interop.Excel.Application)。 我可以设置高度,顶部,。。我的wpf窗口,它的工作很好,但不是在Excel窗口如何设置wpf窗口旁边Excel窗口的大小,以便两者一起填充整个屏幕?

编辑:

我试过这个,但也不起作用:

((ConfiguratorWindowViewModel) DataContext).Manager.App.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlNormal;
((ConfiguratorWindowViewModel) DataContext).Manager.App.ActiveWindow.Height = Screen.PrimaryScreen.Bounds.Height;
((ConfiguratorWindowViewModel) DataContext).Manager.App.ActiveWindow.Width = Screen.PrimaryScreen.Bounds.Width - Width;
两者都将高度设置为不同的值,但不是正确的值,当我像
.Height=800那样硬编码时它也不工作

不幸的是,我无法发布图片来向您展示它的外观和应该的外观

编辑:


这个问题和这个不一样()。我不想更改“外来”应用程序的大小。

假设excel应用程序存储在名为App的变量中。然后你可以这样做:

App.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlNormal;
App.ActiveWindow.Height = Screen.PrimaryScreen.Bounds.Height;
App.ActiveWindow.Width = Screen.PrimaryScreen.Bounds.Width;
Screen类用于获取主屏幕的分辨率

您也可以将窗口最大化:

 App.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized

由于某些原因,它不起作用。它没有在App.ActiveWindow.Height和.Width中输入正确的值。这些值完全不同。