本文介绍了Excel工作簿为C#VSTO激活事件歧义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误:

Error   2   Cannot assign to 'Activate' because it is a 'method group'  
Warning 1   Ambiguity between method 'Microsoft.Office.Interop.Excel._Workbook.Activate()' and non-method 'Microsoft.Office.Interop.Excel.WorkbookEvents_Event.Activate'. Using method group.

我可以使用

myWorkbook.Deactivate += new Excel.WorkbookEvents_DeactivateEventHandler(ThisWorkbook_Deactivate);

因为工作簿没有deactivate()方法.有一个我不想使用的Activate()方法.我想像这样处理工作簿的Activate事件,但出现上面的错误

because there is no deactivate() method for a workbook. There is a Activate() method, which i DO NOT want to use. I'm wanting to handle the workbook Activate event like this, but i get the error above

myWorkbook.Activate += new Excel.WorkbookEvents_ActivateEventHandler(ThisWorkbook_Activate);

有什么想法吗?

推荐答案

查看此处> ://bishoponvsto.wordpress.com/category/vsto/vsto-issues/

"Activate既是Application.Excel的方法又是事件,因此必须将Activate关键字强制转换为事件或方法."

"Activate is both a method and an event of Application.Excel, so the Activate keyword must be cast to either an event or method."

这篇关于Excel工作簿为C#VSTO激活事件歧义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 07:55