c#office开发:Microsoft.office.Tools.Word.Controls.Button出现错误
本文关键字:Button Controls 错误 Word Tools 开发 Microsoft office c#office | 更新日期: 2023-09-27 18:24:30
我正在阅读一篇关于如何使用控制块在word中操作文档的教程
问题在于声明:
private Microsoft.Office.Tools.Word.Controls.Button button = null;
正在给出错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
namespace SecondWordAddIns {
public partial class ThisAddIn {
private Microsoft.Office.Tools.Word.Controls.Button button = null; // error here
private RichTextContentControl richTextControl = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e) { }
private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }
internal void toggleButton() { }
#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
}
}
错误消息:
错误1命名空间"Microsoft.Office.Tools.Word"中不存在类型或命名空间名称"Controls"(是否缺少程序集引用?)C:''Users''root''Documents''Visual Studio 2010''Projects''WordAddIn2''WordAddIn%2''ThisAddIn.cs 14 45 WordAddIn2
首先你需要Microsoft.Office.Tools.Word.v4.0.Utilities.dll。你有吗?
如果是,在解决方案资源管理器中:引用->添加引用->将Microsoft.Office.Tools.Word.v4.0.Utilities引用添加到项目中。
如果您在这一步会遇到一些错误,请阅读谷歌中的"添加对VisualStudio项目的引用"。