简体   繁体   English

如何以编程方式创建Ribbon和向其添加控件?

[英]How to programmatically create Ribbon and add controls to it?

I want to have a single ribbon in microsoft office, in which I will have all my add-ins. 我想在Microsoft Office中拥有一个功能区,在其中我将拥有所有的加载项。 Let's say there are 2 add-ins, both are a single button on the ribbon, which then open a winform. 假设有2个加载项,它们都是功能区上的单个按钮,然后打开一个winform。 The user installs the first add-in, the program checks for an installed ribbon, since there isn't any, it adds the ribbon and the button, which calls the add-ins function. 用户安装第一个加载项,程序检查是否安装了功能区,因为没有功能区,它会添加功能区和按钮,该按钮将调用加载项功能。

Then the user installs the second add-in later, which, instead of adding the same ribbon, checks if there is already a ribbon with the same name installed, and if there is, it only adds the button to the already installed ribbon, if there isn't(somehow the first add-in was uninstalled or something) it adds the ribbon with the button. 然后,用户稍后安装第二个加载项,而不是添加相同的功能区,而是检查是否已经安装了具有相同名称的功能区,如果存在,则仅将按钮添加到已安装的功能区中,如果没有(以某种方式卸载了第一个插件)用按钮添加了功能区。

So I thought that in the ThisAddin_Startup event I instantiate a "RibbonController" class. 因此,我认为在ThisAddin_Startup事件中,我实例化了“ RibbonController”类。 In the RibbonController class i would check for the ribbons existence. 在RibbonController类中,我将检查功能区是否存在。 (Every addin would have a RibbonController class) (每个插件都有一个RibbonController类)

Since I'm fairly new in the MS Office Add-in programming zone, i need help accessing the ribbons objects and creating it programmatically if it wasn't installed earlier. 由于我在MS Office外接程序编程区中还很陌生,因此我需要帮助来访问功能区对象,并在以前未安装的情况下以编程方式创建它。

We use Add In Express at our work place. 我们在工作场所使用Add In Express It's really easy to use and does everything. 它真的很容易使用并且可以做所有的事情。 It's paid though. 它是有偿的。

Also please look at this answer. 也请看看这个答案。

I made a Ribbon.xml for every addin, that has the same structure. 我为每个具有相同结构的插件创建了Ribbon.xml。 I've set a "namespace" in every ribbon.xml, that will help the controls to be added to the same tab, everytime. 我在每个ribbon.xml中都设置了一个“命名空间”,这将有助于每次将控件添加到同一选项卡。

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" xmlns:x="NAMESPACE FOR EVERY TAB"> //the namespaces abreviation is "x"
    <ribbon>
        <tabs>
            <tab idQ="x:tab1" label="CommonTab" >
            ....

Then I set the tabs idQ with the "x:" prefix so it will know the namespace. 然后,我用“ x:”前缀设置选项卡idQ,以便它知道名称空间。 From every add-in that uses the same xml structure, the controls from the tab will be added to a single tab. 对于使用相同xml结构的每个加载项,该选项卡中的控件都将添加到单个选项卡中。

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

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