简体   繁体   English

按需加载excel功能区

[英]Load excel Ribbon on demand

I would like to add functionality to my Excel addin so I could load different Ribbons on demand. 我想向我的Excel加载项添加功能,以便可以按需加载不同的功能区。

At the moment I am trying by exporting the ribbon to XML and loading it 目前,我正在尝试通过将功能区导出到XML并加载它

private Microsoft.Office.Core.IRibbonExtensibility ribbonObj;
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    DialogResult RibbonToLoad = MessageBox.Show("Yes = V2  No = V3", "Select Version", MessageBoxButtons.YesNo);
    switch (RibbonToLoad)
    {
        case DialogResult.Yes:
           ribbonObj = new RibbonV2();
           return ribbonObj;
        case DialogResult.No:
           ribbonObj = new RibbonV3();
           return ribbonObj;
     }

    return new RibbonV2();
}

The problema with this is I cannot find how to switch this Ribbon. 问题是我找不到如何切换此功能区。 I don't find it inside the Globals. 我在Globals.找不到它Globals. object. 宾语。

Also I tried without exporting to XML, but also I couldn't achieve the load on demand of a different ribbon while running(eg clicking a button on a WPF window...) 我也尝试不导出到XML,但是在运行时我无法实现按需加载其他功能区(例如,单击WPF窗口上的按钮...)

Any idea how to get this? 任何想法如何得到这个? I would like to have the possibility of loading different ribbons on the same addin(but only one would be present at once) 我想在同一个插件上加载不同的功能区(但是一次只能出现一个)

You can't manage the process of loading ribbon controls. 您无法管理加载功能区控件的过程。 But you can change visibility of your controls at runtime. 但是您可以在运行时更改控件的可见性。 The IRibbonUI interface provides the Invalidate and InvalidateControl methods that allow to trigger your callbacks where you can change visibility at runtime (getVisible). IRibbonUI界面提供Invalidate和InvalidateControl方法,这些方法允许触发回调,您可以在其中更改运行时的可见性(getVisible)。

In the following example, starting the host application triggers the onLoad event procedure that then calls a procedure which creates an object representing the Ribbon UI. 在以下示例中,启动主机应用程序将触发onLoad事件过程,然后该过程将调用一个过程,该过程将创建代表功能区UI的对象。 Next, a callback procedure is defined that invalidates all of the controls on the UI and then refreshes the UI. 接下来,定义一个回调过程,该过程会使UI上的所有控件无效,然后刷新UI。

The following is the XML markup for Office to load the custom ribbon: 以下是Office加载自定义功能区的XML标记:

<customUI … onLoad=”MyAddInInitialize” …>

The following is the callback method for the onLoad event: 以下是onLoad事件的回调方法:

Dim MyRibbon As IRibbonUI

Sub MyAddInInitialize(Ribbon As IRibbonUI)
    Set MyRibbon = Ribbon
End Sub

Sub myFunction()
    ‘ Invalidates the caches of all of this add-in’s controls 
    MyRibbon.Invalidate()            
End Sub

You can read more about the Ribbon UI in the following series of articles in MSDN: 您可以在MSDN的以下系列文章中阅读有关Ribbon UI的更多信息:

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

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