Como criar um suplemento de automação do Excel em c # que envolve uma função RT
Tenho um suplemento de automação baseado em RtdServer:
Como criar um suplemento de automação do Excel em tempo real em C # usando o RtdServe.
Criar um wrapper VBA é trivial:
Function RtdWrapper(start)
RtdWrapper = Excel.Application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", "", start)
End Function
Isso funciona. Eu tentei criar um wrapper C # da seguinte maneira:
[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");
}
}
Quando insiro "= Countdown (150)" em uma célula no Excel, ele mostra o valor inicial de 150 retornado pelo ConnectData, mas nunca é atualizado. Existe algum retorno de chamada que eu devo registrar? Estou instanciando o objeto Aplicativo corretamente? O que estou perdendo
Obrigado
Frank