我有一个基于RtdServer的自动化插件:
How do I create a real-time Excel automation add-in in C# using RtdServer?。
创建一个VBA包装器很简单:
Function RtdWrapper(start)
RtdWrapper = Excel.Application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", "", start)
End Function这是可行的。我尝试创建一个C#包装器,如下所示:
[ClassInterface(ClassInterfaceType.AutoDual)]
public class RtdWrappers
{
private readonly Microsoft.Office.Interop.Excel.Application _application = new Application();
public object Countdown(object startingCount)
{
var start = Convert.ToInt32(startingCount.ToString());
return _application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", string.Empty, start);
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" + t.GUID.ToString().ToUpper() + "}\\Programmable");
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey("CLSID\\{" + t.GUID.ToString().ToUpper() + "}\\Programmable");
}
}当我在Excel的单元格中输入"=Countdown( 150 )“时,它会显示初始值150,该值由ConnectData返回,但从不更新。有没有我应该注册的回调?我是否正确地实例化了Application对象?我遗漏了什么?
谢谢,
弗兰克
发布于 2011-03-28 00:44:30
实际上,您并没有获得正确的Application对象。一种解决方案是在外接程序中实现IDTExtensibility2接口。此接口有一个OnConnection方法,Excel将在加载外接程序时调用该方法。在此方法中,将向您传递Application对象,您可以将其保留在局部变量中以供以后使用。
https://stackoverflow.com/questions/5398152
复制相似问题