Outlook 中的 XML 功能区 - 使其显示在特定窗口上
我第一次尝试使用 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
}
}
I'm making my first attempt at creating a Ribbon in Outlook using XML and am having trouble locating specifically how to tell my add-in that I only want the ribbon to appear on Explorer windows.
Advice?
Thanks.
my Ribbon1.XML file:
<?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>
The magical error box that pops up says:
CustomUI Runtime Error in testingOLaddin2
Error found in CustomUI XML of "testingOLaddin2"
Line: 3
Column: 10
Error Code 0x80004005
Failed to find Office control by ID
ID: TabMail
Per request, my ribbon generation code:
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您用于创建插件和功能区的方法。如果您使用该
方法,则只需在 RibbonId 参数的值为
Edit
时返回功能区 xml 即可完成此操作,代码中的以下更改可能有效:
This depends on the method you use to create the addin and ribbon. If you are using the
method you could accomplish this by only returning the ribbon xml if the RibbonId parameter has the value
Edit
Following change in your code might work:
当您在
ThisAddIn
类中实现CreateRibbonExtensibilityObject()
以返回功能区类的新实例时,Outlook 将调用您的GetCustomUI(string RibbonId)
。功能区类是您引用 XML 的位置(在GetCustomUI
中)。对于 XML 本身,您需要单独引用每个 Outlook 资源管理器类型。不幸的是,据我所知,没有一种总体方法可以在 Ribbon XML 语法中指定“所有资源管理器”。
以下是一些引用邮件和日历浏览器的示例:
Microsoft 确实给出了一些有关内置选项卡的 idMso 属性的提示,但不幸的是它被隐藏在这个 Excel 电子表格中:链接
Your
GetCustomUI(string RibbonId)
Is called by Outlook once you implemenentCreateRibbonExtensibilityObject()
in theThisAddIn
class to return a new instance of your ribbon class. The ribbon class is where you reference the XML (inGetCustomUI
).For the XML itself, you will need to reference each Outlook explorer type individually. Unfortunately, there isn't an overarching way to specify "all explorers" in the Ribbon XML syntax, as far as I know.
Here are some examples referencing the Mail and Calendar explorers:
Microsoft does give some hint about
idMso
attributes for built-in tabs, but unfortunately it's buried in this Excel spreadsheet: link