【发布时间】:2012-07-31 12:20:56
【问题描述】:
我有一个可用的基于 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)”时,它会显示 ConnectData 返回但从不更新的初始值 150。我应该注册一些回调吗?我是否正确实例化了 Application 对象?我错过了什么?
谢谢,
弗兰克
【问题讨论】:
标签: c# vsto excel-addins rtd excel-udf