Outlook中的XML功能区 - 使其显示在特定窗口中

时间:2011-05-12 19:26:47

标签: c# .net outlook ribbon

我正在尝试使用XML在Outlook中创建功能区,但我无法找到具体的方法来告诉我的加载项我只希望功能区显示在资源管理器窗口中。

么?

感谢。

我的Ribbon1.XML文件:

    <?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="My Group">
          <button idMso="Delete"/>
        </group>
      </tab>
      <tab idMso="TabMail">
        <group idMso="GroupMoveActions"
               visible="false">
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

弹出的神奇错误框说:

testingOLaddin2中的CustomUI运行时错误

Error found in CustomUI XML of "testingOLaddin2"

Line: 3
Column: 10
Error Code 0x80004005
Failed to find Office control by ID
ID: TabMail

每个请求,我的功能区生成代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Office = Microsoft.Office.Core;

using System.Diagnostics;

namespace testingOLaddin2
{
    [ComVisible(true)]
    public class Ribbon1 : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public Ribbon1()
        {
        }

        #region IRibbonExtensibility Members

        public string GetCustomUI(string ribbonID)
        {
            return GetResourceText("testingOLaddin2.Ribbon1.xml");
        }

        #endregion

        #region Ribbon Callbacks
        //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1

        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
        }


        #endregion

        #region Helpers

        private static string GetResourceText(string resourceName)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            string[] resourceNames = asm.GetManifestResourceNames();
            for (int i = 0; i < resourceNames.Length; ++i)
            {
                if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                {
                    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                    {
                        if (resourceReader != null)
                        {
                            return resourceReader.ReadToEnd();
                        }
                    }
                }
            }
            return null;
        }

        #endregion
    }
}

2 个答案:

答案 0 :(得分:9)

这取决于您用于创建插件和功能区的方法。如果您正在使用

IRibbonExtensibility.GetCustomUI(string RibbonId)

如果RibbonId参数的值为

,只需返回功能区xml即可实现此方法
"Microsoft.Outlook.Explorer"

修改

您的代码中的更改可能有效:

public string GetCustomUI(string ribbonID)
{
  if (ribbonID == "Microsoft.Outlook.Explorer")
    return GetResourceText("testingOLaddin2.Ribbon1.xml");

  return null; // if problems here, try return string.Empty
}

答案 1 :(得分:2)

一旦您在GetCustomUI(string RibbonId)类中实现CreateRibbonExtensibilityObject()以返回功能区类的新实例,您的ThisAddIn将被Outlook调用。功能区类是您引用XML的地方(在GetCustomUI中)。

对于XML本身,您需要单独引用每个Outlook资源管理器类型。不幸的是,据我所知,在Ribbon XML语法中没有一种指定“所有探索者”的总体方法。

以下是引用邮件和日历资源管理器的一些示例:

<?xml version="1.0" encoding="UTF-8"?>
<customUI  xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab idMso="TabCalendar">
      <!-- Calendar tab controls go here -->
      </tab>
      <tab idMso="TabMail">
      <!-- mail tab controls go here -->
      </tab>
    </tabs>
  </ribbon>
</customUI>

Microsoft确实对内置选项卡的idMso属性提供了一些提示,但不幸的是,它隐藏在此Excel电子表格中:link