Excel 2016的多个实例中的自定义任务窗格 [英] Custom Task Pane in mutiple instances of Excel 2016

查看:343
本文介绍了Excel 2016的多个实例中的自定义任务窗格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为自定义任务窗口编写代码,如<&p>

https 中所述 // msdn.microsoft.com/en-us/library/bb608590.aspx


一切运作良好我可以打开和关闭任务窗格。 但是,如果我打开一个新的Excel实例 - 所以说第一个实例是Excel1,第二个是Excel2,每个实例都打开了自己的工作簿,任务窗格将永远不会出现在Excel2中;切换按钮
将打开和关闭Excel1中的任务窗格并使用Excel1中的数据...


我正在寻找关于如何关联的任何想法带有第二个或更多Excel实例的自定义任务窗格。 





解决方案

您好,


您可以在WorkbookActivate事件中创建用于存储工作簿及其相关任务窗格的新字典。


请创建一个新按钮或togglebutton,然后测试下面的代码:

 public CustomTaskPane taskPane; 
public Dictionary< string,CustomTaskPane> WbCtp = new Dictionary< string,CustomTaskPane>();

private void ThisAddIn_Startup(object sender,System.EventArgs e)
{
this.Application.WorkbookActivate + = Application_WorkbookActivate;

}

private void Application_WorkbookActivate(Excel.Workbook Wb)
{
var wbCtp = WbCtp.Where(wb => wb.Key = = Wb.FullName).FirstOrDefault()值。
if(wbCtp == null)
{
Globals.Ribbons.Ribbon.toggleButton1.Checked = false;
taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new WinForm()," My task pane");
WbCtp.Add(Wb.FullName,taskPane);
}
其他
{
taskPane = wbCtp;
}
}


 

 private void toggleButton1_Click(object sender,RibbonControlEventArgs e)
{
var taskPane = Globals.ThisAddIn.taskPane;
if(taskPane!= null)
{
taskPane.Visible =!taskPane.Visible;
}
}

问候,


Celeste



I am trying to write code for a custom taskpane as outlined in 

https://msdn.microsoft.com/en-us/library/bb608590.aspx

All works well and I can open and close the taskpane.  But, if I open a new instance of Excel - so say the first instance is Excel1 and the second is Excel2 each with their own workbooks open, the taskpane will never appear in Excel2; the toggle button will open and close the taskpane in Excel1 and use the data from Excel1 one as well...

I am looking for any ideas as to how to associate the custom taskpane with a second or more instances of Excel. 

解决方案

Hello,

You could create a new dictionary used to store the Workbook and its related taskpane in the WorkbookActivate event.

Please create a new button or togglebutton and then test the code below:

     public CustomTaskPane taskPane;
        public Dictionary<string, CustomTaskPane> WbCtp = new Dictionary<string, CustomTaskPane>();

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.WorkbookActivate += Application_WorkbookActivate;
       
        }

        private void Application_WorkbookActivate(Excel.Workbook Wb)
        {
                var wbCtp = WbCtp.Where(wb=>wb.Key==Wb.FullName).FirstOrDefault().Value;
                if (wbCtp == null)
                {
                    Globals.Ribbons.Ribbon.toggleButton1.Checked = false;
                    taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new WinForm(), "My task pane");              
                    WbCtp.Add(Wb.FullName, taskPane);
                }
                else
                {
                   taskPane = wbCtp;
                }
        }

 

        private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
        {
            var taskPane = Globals.ThisAddIn.taskPane;
            if (taskPane != null)
            {
                taskPane.Visible = !taskPane.Visible;
            }          
        }

Regards,

Celeste


这篇关于Excel 2016的多个实例中的自定义任务窗格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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