【发布时间】:2015-02-26 04:43:03
【问题描述】:
我在文章here 之后创建了一个Word 插件。我按 F5 并运行项目,它按预期工作,我认为插件已安装在我的机器中。所以,现在我打开另一个 Word 2007 实例并创建一个文档,但我没有看到该代码在新文档上工作。我错过了什么吗?
以下是我正在使用的代码:-
using Word = Microsoft.Office.Interop.Word;
namespace WordAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.DocumentBeforeSave +=
new Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
{
Doc.Paragraphs[1].Range.InsertParagraphBefore();
Doc.Paragraphs[1].Range.Text = "Text was added by using code.---";
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
来自here:- 当您完成项目开发后,请从您的开发计算机中删除插件程序集、注册表项和安全设置。否则,每次在开发计算机上打开 Word 时,加载项都会继续运行。 在开发计算机上清理已完成的项目 在 Visual Studio 的 Build 菜单上,单击 Clean Solution。
现在,当我不清理解决方案时,我应该一直拥有 Word 2007 的加载项,对吗?我根本看不到这种情况发生。
【问题讨论】: