C# Tips: 解决Office PIA编程中的方法冲突

欲调用Excel.Worksheet的Activate方法,结果遇到了以下Warning:

Ambiguity between method 'Microsoft.Office.Interop.Excel._Worksheet.Activate()' and non-method 'Microsoft.Office.Interop.Excel.DocEvents_Event.Activate'. Using method group.


如果不解决这个Warning,运行中也不会出错,但是留着一个warning毕竟看着不舒服。解决办法很简单:

报出警告的代码是:

this.LatestWorksheet.Activate();
相关定义:

using Excel = Microsoft.Office.Interop.Excel;

/// <summary>
/// Gets latest Worksheet instance in last operating.
/// </summary>
public Excel.Worksheet LatestWorksheet { get; private set; }


改成这样的就可以了:

((Excel._Worksheet)this.LatestWorksheet).Activate();

相关链接:

  • http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/ee876f42-d4c0-4873-83f8-d7b4bbca7030/
  • http://blogs.msdn.com/b/eric_carter/archive/2004/09/20/231982.aspx




你可能感兴趣的:(编程,c,Excel,C#,Office)