我在Excel-DNA 0.32遇到了CustomTaskPaneFactory最奇怪的问题。
当我创建具有从模板化任务窗格(MyCTP<T>)继承的类(MyIntCTP)的任务窗格时,CustomTaskPaneFactory会引发异常。
下面是一个说明上下文的示例:
<DnaLibrary RuntimeVersion="v4.0" Language="CS">
<Reference Path="System.Windows.Forms.dll" />
<![CDATA[
using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;
using System.Windows.Forms;
internal class ThisAddIn : IExcelAddIn
{
public void AutoOpen()
{
var p = CustomTaskPaneFactory.CreateCustomTaskPane(typeof(MyIntCTP), "o");
p.Visible = true;
}
public void AutoClose()
{ }
}
public class MyCTP<T> : UserControl
{ }
public class MyIntCTP : MyCTP<int>
{ }
]]>
</DnaLibrary>上面的代码不起作用。具有以下System.Runtime.InteropServices.COMException的CreateCustomTaskPane上的Excel-DNA崩溃
Unable to create specified ActiveX control
at ExcelDna.Integration.CustomUI.ICTPFactory.CreateCTP(String CTPAxID, String CTPTitle, Object CTPParentWindow)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(String controlProgId, String title, Object parent)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(Type userControlType, String title, Object parent)
at ExcelDna.Integration.CustomUI.CustomTaskPaneFactory.CreateCustomTaskPane(Type userControlType, String title)
[...]但是,如果父任务窗格(MyCTP)实现了一个接口,则它确实可以工作(请注意,所有类都标记为公共):
public interface DummyInterface
{ }
public class MyCTP<T> : UserControl, DummyInterface
{ }我不需要界面,但我想保留模板。有什么想法吗?
发布于 2015-10-16 00:34:57
我也遇到过同样的问题。
解决方案是com可见性,然后它将传递COM(Active X)对象。
[ComVisible(true)]
public class MyIntCTP : MyCTP<int>
{ }尝试下面的链接,它们会给你一个概述,这将会有所帮助。https://msdn.microsoft.com/en-us/library/aa942861.aspx
请看一下下面给出的git链接,以帮助进行项目。https://github.com/KevinT/ExcelDna/blob/master/Distribution/Samples/CustomTaskPane.dna
https://stackoverflow.com/questions/28030009
复制相似问题