gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:33:45 25 4
gpt4 key购买 nike

我第一次尝试使用 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>

弹出的神奇错误框说:

测试 OLaddin2 时出现 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
}
}

最佳答案

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

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
}

关于c# - Outlook 中的 XML 功能区 - 使其显示在特定窗口中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5983381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com