C#显示隐藏Excel窗口 [英] C# show hide Excel window

查看:388
本文介绍了C#显示隐藏Excel窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Excel开发一个C#add(使用VSTO工具)。我有一个异步进程运行,它不时弹出通知的气泡,显示在任何栏附近的所有窗口。



我可以绑定一个事件点击这些弹出的气泡。如果Excel添加在用户点击时被隐藏,我想显示Excel窗口并导航到某个表单。



这是可能吗?

解决方案

您可以通过以下代码找到Excel实例:

  oExcelApp =(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject(Excel.Application); 

(此主题的更多信息:使用C#通过句柄获取Excel应用程序的实例



您可能需要检查Excel对用户是否可见:

  oExcelApp .Visible = true; 

此代码段可激活您想要的工作表:

  oExcelApp.Worksheet sheet =(oExcelApp.Worksheet)this.Sheets [Sheet2]; 
sheet.Select(Type.Missing);


I am developing a C# add in for Excel (using VSTO tools). I have an asynchronous process running, that pops up from time to time notification bubbles that are shown above all windows close to the taskbar.

I am able to bind an event to the click on these bubbles that pop up. If the Excel add in is hidden when the user clicks, I'd like to show the Excel window and navigate to a certain sheet.

Is this possible ?

解决方案

You can find the Excel instance running thanks to this code:

oExcelApp =  (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");

(more info on this thread: Get instance of Excel application with C# by Handle)

You may have to check if Excel is visible to the user:

oExcelApp .Visible = true;

And this snippet to activate the sheet you want:

oExcelApp.Worksheet sheet = (oExcelApp.Worksheet)this.Sheets["Sheet2"];
sheet.Select(Type.Missing);

这篇关于C#显示隐藏Excel窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆