我目前正在尝试禁用Microsoft 2016的“文件”菜单中的几个命令。
目前我有:
Main.cs:
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon();
}Ribbon.cs:
public string ReturnUI()
{
return GetSource("Ribbon.xml");
}
private static string GetSource(string sourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] sourceNames = asm.GetManifestSourceNames();
for (int x = 0; x < sourceNames.Length; ++x)
{
if (string.Compare(sourceName, sourceNames[x], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader sr = new StreamReader(asm.GetManifestSourceStream(sourceNames[x])))
{
if (sr != null)
{
return sr.ReadToEnd();
}
}
}
}
return "";
}Ribbon.xml:
<commands>
<command idMso="FileSaveAs" enabled="false" />
</commands>
<backstage>
<tab idMso ="TabNew" visible="false"/>
</backstage>我相信我有目前所有的参考资料,但也许没有:
这不会禁用“文件”菜单下的“另存为”或我选择的任何其他选项。我遗漏了什么?没有正确连接的东西?过时的东西?
发布于 2018-03-23 17:58:26
你没做错什么。问题在于后台,因为它是为Word 2013及以后设计的。不可能直接重新使用后台命令。您显示的代码将用于调用FileSaveAs的任何丝带按钮或键盘快捷键,但不适用于后台。
在后台,您可以使用两种基本方法:
DocumentBeforeSave事件可能会有所帮助。如果您对第一个选项感兴趣,我推荐这两篇MSDN文章,它们深入地描述了如何使用Ribbon:Office 2010开发人员后台视图简介,为开发人员定制Office 2010后台视图的后台工作。您可以下载Office 2013的控件ID列表:https://www.microsoft.com/en-us/download/details.aspx?id=36798
由于很难重建Save选项卡的全部内容,许多人决定使用DocumentBeforeSave事件。
https://stackoverflow.com/questions/49452474
复制相似问题