简体   繁体   English

如何在C#中以编程方式还原最小化的Excel

[英]How to restore a minimized excel programmatically in c#

I want to activate or make it visible(restore) of an existing open/minimized excel using a button click to avoid user open in another new instance. 我想使用按钮单击来激活或使其显示(还原)现有打开/最小化的excel,以避免用户在另一个新实例中打开。

For example, an workbook_A was minimized, the user click a button and the workbook_A will restored as usual instead of open in another new instance. 例如,最小化一个workbook_A,用户单击一个按钮,该workbook_A将照常还原,而不是在另一个新实例中打开。

I tried to use below codes: 我尝试使用以下代码:

Excel.Application oExcelApp;
this.Activate();
oExcelApp =     (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
oExcelApp.Visible = true;

But it's only open the empty excel.application, any idea how can I restore back my opened excel? 但这只是打开空的excel.application,知道如何恢复打开的excel吗?

Please advice.. Thanks 请指教..谢谢

Just simply go through workbooks collection and make their window state = maximaze like that 只需简单地浏览工作簿集合,并使它们的窗口状态=最大化

foreach (Excel.Workbook item in oExcelApp.Workbooks)
{
  item.Windows[1].WindowState = Excel.XlWindowState.xlMaximized;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM