自定义菜单不适用于少量文档 [英] Custom menu is not comming for few documents

查看:103
本文介绍了自定义菜单不适用于少量文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

Hello All,

我正面临着Word Addin中的一个奇怪问题。

I'm facing a strange problem in Word Addin.

背景

应用程序是文档存储库的类型。它具有单独的winform UI,允许用户搜索/添加文档到此存储库。用户可以搜索现有的word / Excel文档,也可以查看/编辑相同的文档。有一个单独的单词addin项目,
陷阱单词事件并执行所需的操作。

The application is type of document repository. it has seperate winform UI which allows user to search/add document to this repository. User can search existing word/Excel documents and can View/Edit the same. There is a seperate word addin project which traps word events and perform required operation.

问题:

我的插件代码是将自定义菜单添加到Application_startup上的自定义模板。它出现在之后创建或打开的所有文档中。但对于一些文件,它没有出现。这不是不一致的,但是我的机器上的这些
特定单词文件不会出现。

My addin code is adding custom menu to a custom template on Application_startup. It is appearing for all the documents being created or opened after that. But for some documents its not appearing. It's not inconsistent but it doesn't appear for these specific word documents on my machine.

其他信息: 在我的机器上造成问题的同一文档在某些不同的开发机器上工作正常。

Additional info: The same document which is causing problem on my machine is working fine on some different dev machine.

代码:


 private Word.Template customTemplate;

 private Office.CommandBarButton newSubmenu = null;

 public Word.Application applicationObject;

 private object missing = System.Type.Missing;

 private string menuTag = "myMenu";



 private void ThisAddIn_Startup(object sender, System.EventArgs e)

 {

 myApplication = this.Application;



 GetCustomTemplate();

 RemoveExistingMenuItem();

 AddMenuItem();

 }

 private void GetCustomTemplate()

 {

 object TemplatePath = ConfigurationManager.AppSettings["WordCustomTemplatePath"];

 object install = true;



 foreach (Word.Template installedTemplate in applicationObject.Templates)

 {

 if (installedTemplate.FullName == (string) TemplatePath)

  install = false;

 }



 if ((bool)install)

 applicationObject.AddIns.Add(TemplatePath.ToString(), ref install);

 customTemplate = applicationObject.Templates.get_Item(ref TemplatePath);

 }



private void RemoveExistingMenuItem()

{

 Office.CommandBar contextMenu = applicationObject.CommandBars["File"];



 applicationObject.CustomizationContext = customTemplate;

 Office.CommandBarButton control = (Office.CommandBarButton)contextMenu.FindControl(Office.MsoControlType.msoControlButton, missing, menuTag, true, true);



 if ((control != null))

 control.Delete(true);

 }



 private void AddMenuItem()

{

 try

 {

 applicationObject.CustomizationContext = customTemplate;

 Office.MsoControlType menuItem = Office.MsoControlType.msoControlButton;

 Office.CommandBarPopup fileMenu = (Office.CommandBarPopup)applicationObject.CommandBars.FindControl



  (Office.MsoControlType.msoControlPopup, 30002, missing, missing);

 newSubmenu = (Office.CommandBarButton)fileMenu.Controls.Add(

   Office.MsoControlType.msoControlButton, missing, missing, 6, false);

 if (newSubmenu != null)

 {

 newSubmenu.Caption = "Save As New MyApplication Document..";

 newSubmenu.Tag = menuTag;

 newSubmenu.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(newSubmenu_Click);

 newSubmenu.Enabled = true;

 newSubmenu.Visible = true;

 }

 GC.Collect();

 }

 catch (Exception exception)

 {

 //Log("Error adding menu :" + exception.Message);

 }

 finally

 {

 customTemplate.Saved = true;

 }

 }



 void newSubmenu_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)

 {

 //Do something

 }



推荐答案

问题的原因在于加载项的环境和/或上下文的差异因为它在其他系统上成功运行,并且无法在您的开发系统上正常运行。您可以比较每个服务级别和更新受到加载项影响的所有应用程序的版本
的更新。每个,并运行两个系统的ProcMon并比较日志 - 这是严格和乏味的。 另一个因素可能是使用Word在后台处理多个
文件的其他应用程序的影响。这种情况不受支持,可能会产生不可预见的后果。 请参阅Microsoft知识库文章


257757 服务器端自动化办公室的注意事项

http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757 功能

唯一的解决方法可能是您已经实施的解决方法。希望这很有用。

The only workaround could be the one you have already implemented. Hope this is helpful.


这篇关于自定义菜单不适用于少量文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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