开发者

How can I resolve the ambiguity in this Microsoft.Office.Excel method call?

开发者 https://www.devze.com 2023-01-09 04:43 出处:网络
I am using office 2007 excel work sheet function in c# code. VS2010 issues this warning Warning3Ambiguity between method

I am using office 2007 excel work sheet function in c# code. VS2010 issues this warning

Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Excel._Worksheet.Activate()' and non-method 'Microsoft.Office.Interop.Excel.DocEvents_Event.Activate'. Using method group. D:\EXLANEDB01p\dev\libraries\EXCEL\Excel.cs 531 95 EXCEL

How do I resolve this ? the call is

xSheet.Activate(); 

where xSheet passed as ref in the call as

ref Microsoft.Offic开发者_开发技巧e.Interop.Excel.Worksheet xSheet


You need to disambiguate the Activate name. Within the Worksheet interface, Activate is either a method (if looked at as a _Worksheet object) or an event (if looked at as a DocEvents_Event object).

Cast your object to Microsoft.Office.Interop.Excel._Worksheet first then call Activate().

((Microsoft.Office.Interop.Excel._Worksheet)xSheet).Activate();

Or declare a new _Worksheet variable and use that within your method.

_Worksheet sheet = xSheet;
sheet.Activate();

Otherwise you could change your method declaration to take a reference to a _Worksheet instead of a Worksheet as well as all associated declarations.

void MyMethod(ref Microsoft.Office.Interop.Excel._Worksheet xSheet)
{
    // ...
}

// usage:
_Worksheet sheet = new Worksheet();
MyMethod(ref sheet);
0

精彩评论

暂无评论...
验证码 换一张
取 消