Excel加载项C#获取活动单元格的值

我使用了Visual Studio 2013加载项模板,并使用一个简单的button创build了一个自定义任务窗格。 现在我正试图读取当button被按下时活动单元格的值。 这是我迄今为止:

namespace CostCenterAddIn { public partial class CostCenterControl : UserControl { public CostCenterControl() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Excel.Window W = this.Application.ActiveWindow as Excel.Window; Excel.Range R = W.ActiveCell as Excel.Range; MessageBox.Show(R.Text.ToString()); } } } 

我复制了这个例子: 使用VSTO读取Excel中的ActiveCell内容

但是,我收到以下错误:

'CostCenterAddIn.CostCenterControl'不包含'Application'的定义,并且没有find接受'CostCenterAddIn.CostCenterControl'types的第一个参数的扩展方法'Application'(你缺lessusing指令还是程序集引用?)

出于某种原因,我无法访问应用程序。

这是我的代码“ThisAddIn.cs”:

  namespace CostCenterAddIn { public partial class ThisAddIn { private CostCenterControl myUserControl1; private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane; private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WorkbookBeforeSave += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave); myUserControl1 = new CostCenterControl(); myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "Cost Center Converter"); myCustomTaskPane.Visible = true; } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #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 } } 

任何意见将不胜感激!