Office加载色带:同一选项卡与2加载项 [英] Office add-in ribbons: same tab with 2 addins

查看:276
本文介绍了Office加载色带:同一选项卡与2加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出两个词插件团体出现在同一选项卡(工具),但它们都创造出独特的标签(有两个工具选项卡)。我saw这个视频但我使用了可视化设计,而不是XML。

I'm trying to make two word add-ins' groups to appear in the same tab (Tools) but they both create unique tabs (there's two 'Tools' tabs). I saw this video but I'm using the Visual Designer, not XML.

我可以编辑设计code以某种方式,使这项工作?

Can I edit the designer code in some way to make this work?

推荐答案

<一个href="http://blogs.msdn.com/b/vsto/archive/2008/03/10/share-a-ribbon-customization-between-office-applications.aspx" rel="nofollow">http://blogs.msdn.com/b/vsto/archive/2008/03/10/share-a-ribbon-customization-between-office-applications.aspx

的Office 2007

创建功能区

  1. 创建在Visual Studio 2007的Excel,Outlook中,PowerPoint或Word项目。对于这些步骤的目的,创建一个C#项目,该项目命名为RibbonStarterProject。
  2. 添加功能区(可视化设计)项目到项目中。对于这些步骤的目的,接受默认名称Ribbon1。
  3. 保存并关闭该项目。

创建一个类库项目

  1. 创建在Visual Studio中的一个新的类库项目。对于这些步骤的目的,该项目命名为SharedRibbonLibrary。
  2. 添加项目引用Microsoft.Office.Tools.Common.v9.0组装。
  3. 在Visual Studio中的项目菜单,单击添加现有项。
  4. 在添加现有项对话框中,浏览到RibbonStarterProject项目目录,选择Ribbon.cs文件,然后单击添加。 Ribbon1.cs被复制到项目目录并显示在解决方案资源管理器中的项目节点下方。
  5. 双击Ribbon1.cs。 显示功能区设计。
  6. 从Office功能区控件工具箱选项卡,将一个按钮拖到组1。
  7. 单击按钮1将其选中。
  8. 在属性窗口中设置修饰符为public。 注:默认情况下,控制您添加到功能区的内部。这使得他们只能访问同一个组件内code。但是,当您访问这些控件,您将通过程序集引用访问它们。因此,从code到达,你必须让他们公开。更多关于这个很快。
  9. 右键单击功能区设计,然后单击属性。
  10. 在属性窗口中,单击RibbonType属性,然后选择功能区的ID中,要显示功能区中的应用程序或Outlook检查器窗口。有关此属性的详细信息,请参阅MSDN参考主题为RibbonType属性。
  11. 在Solution Explorer中,用鼠标右键单击Ribbon1.cs,然后单击查看code。
  12. 更改类SharedRibbonLibrary的命名空间
  13. 重复的Ribbon1.designer.cs文件这一步。
  14. 编译并保存SharedRibbonLibrary项目。现在,您可以使用生成的程序集的支持功能区的任何VSTO项目。
  1. Create a new class library project in Visual Studio. For the purpose of these steps, name the project SharedRibbonLibrary.
  2. Add a project reference to the Microsoft.Office.Tools.Common.v9.0 assembly.
  3. On the Project Menu in Visual Studio, click Add Existing Item.
  4. In the Add Existing Item dialog box, browse to the "RibbonStarterProject" project directory, select the Ribbon.cs file, and click Add. Ribbon1.cs is copied to the project directory and appears beneath the project node in Solution Explorer.
  5. Double-click Ribbon1.cs. The Ribbon designer appears.
  6. From the Office Ribbon Controls tab of the Toolbox, drag a button onto group1.
  7. Click button1 to select it.
  8. In the Properties window, set Modifiers to Public. Note: By default, controls that you add to the Ribbon are Internal. That makes them only accessible to code inside the same assembly. However, when you access these controls, you will be accessing them through an assembly reference. Therefore, to reach them from code, you must make them public. More on this soon.
  9. Right-click the Ribbon designer, and then click Properties.
  10. In the Properties window, click the RibbonType property, and then select the Ribbon ID’s of the applications or Outlook Inspector windows in which you want the Ribbon to appear. For more information about this property, see the MSDN reference topic for the RibbonType property.
  11. In Solution Explorer, right-click Ribbon1.cs, and then click View Code.
  12. Change the namespace of the class to "SharedRibbonLibrary".
  13. Repeat this step for the Ribbon1.designer.cs file.
  14. Compile and save the SharedRibbonLibrary project. You can now use the resulting assembly in any VSTO project that supports the Ribbon.

消费功能区自定义

  1. 创建的Excel 2007中,Outlook,PowerPoint或Word中的项目。
  2. 添加引用SharedRibbonLibrary组装。
  3. 添加以下code到的ThisAddIn,的ThisWorkbook或ThisDocument类项目的。这code覆盖CreateRibbonExtensibilityObject方法,并返回功能区的Office应用程序。

  1. Create 2007 Excel, Outlook, PowerPoint, or Word project.
  2. Add a reference to the SharedRibbonLibrary assembly.
  3. Add the following code to the ThisAddin, ThisWorkbook, or ThisDocument class of your project. This code overrides the CreateRibbonExtensibilityObject method and returns the Ribbon to the Office application.

protected override Microsoft.Office.Core.IRibbonExtensibility
CreateRibbonExtensibilityObject()
{
     return new Microsoft.Office.Tools.Ribbon.RibbonManager(
     new Microsoft.Office.Tools.Ribbon.OfficeRibbon[] { new       
        SharedRibbonLibrary.Ribbon1() });

}

  • 添加一个新类到项目中。接受默认名称的Class1.cs。

  • Add a new class to the project. Accept the default name "Class1.cs".

    用以下替换code。在Class1的文件:

    Replace the code in the Class1 file with the following:

     partial class ThisRibbonCollection :    Microsoft.Office.Tools.Ribbon.RibbonReadOnlyCollection
    {
     internal SharedRibbonLibrary.Ribbon1 Ribbon1
     {
         get { return this.GetRibbon<SharedRibbonLibrary.Ribbon1>(); }
     }
    }
    

  • 确定 - 你完成了!您现在可以访问功能区和您添加到功能区在code。该按钮。让我们试着通过处理事件中的消费项目。

    Ok – You are done! You can now access the Ribbon and the button that you added to the Ribbon in your code. Lets try by handling an event in the consuming project.

    处理按钮点击事件

    1. 添加以下code项目的启动事件处理程序。

    1. Add the following code to the startup event handler of project.

    Globals.Ribbons.Ribbon1.button1.Click += new EventHandler<Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs>(button1_Click);
    

  • 以下事件处理程序添加到您的项目:

  • Add the following event handler to your project:

    void button1_Click(object sender,
    Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e)
    {
    System.Windows.Forms.MessageBox.Show("I can handle events!");
    }
    

  • 运行项目。

  • Run the project.

    在Office应用程序打开时,单击加载项选项卡,然后单击按钮。 出现一条消息,说我能处理的事件!

    When the Office application opens, click the Add-Ins tab, and then click your button. A message that says "I can handle events!" appears.

    的Office 2010 执行:<一href="http://blogs.msdn.com/b/vsto/archive/2010/06/23/sharing-a-ribbon-customization-between-office-projects-in-visual-studio-2010-mclean-schofield.aspx" rel="nofollow">http://blogs.msdn.com/b/vsto/archive/2010/06/23/sharing-a-ribbon-customization-between-office-projects-in-visual-studio-2010-mclean-schofield.aspx

    2010年实现实际添加的两大功能区 - 每个加载项。我相信本文仅适用于加载项在相同功能区不同的Office产品(如Word和Excel)不是两个Excel加载项。

    The 2010 implementation actually add's two Ribbons - one for each Add-In. I believe the article is only applicable to Add-Ins on the same Ribbon in different Office products (eg Word and Excel) not two Excel Add-ins.

    其他唯一的途径,我发现是一个第三方组件:<一href="http://www.add-in-ex$p$pss.com/creating-addins-blog/2012/11/05/excel-addin-shared-ribbon-tabs/" rel="nofollow">http://www.add-in-ex$p$pss.com/creating-addins-blog/2012/11/05/excel-addin-shared-ribbon-tabs/

    The only other avenue I've found is a 3rd party component: http://www.add-in-express.com/creating-addins-blog/2012/11/05/excel-addin-shared-ribbon-tabs/

    这篇关于Office加载色带:同一选项卡与2加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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