我正在阅读 tutorial on how to use control blocks to manipulate document in 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
}
}
错误信息:
Error 1 The type or namespace name 'Controls' does not exist in the namespace 'Microsoft.Office.Tools.Word' (are you missing an assembly reference?) C:\Users\root\Documents\Visual Studio 2010\Projects\WordAddIn2\WordAddIn2\ThisAddIn.cs 14 45 WordAddIn2
最佳答案
首先您需要 Microsoft.Office.Tools.Word.v4.0.Utilities.dll。您有吗?
如果是的话, 在您的解决方案资源管理器中: 引用-> 添加引用 -> 将 Microsoft.Office.Tools.Word.v4.0.Utilities 引用添加到您的项目中。
如果您在此步骤中遇到一些错误,请阅读 Google 中的“添加对 Visual Studio 项目的引用”。
关于C# Office Development : Microsoft. Office.Tools.Word.Controls.Button 给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26055798/