Question

J'ai un complément d'automatisation basé sur RTDServer fonctionnel:
Comment créer un complément d'automatisation Excel en temps réel en C # à l'aide de RTDServer?.

La création d'un emballage VBA est trivial:

Function RtdWrapper(start)
    RtdWrapper = Excel.Application.WorksheetFunction.RTD("StackOverflow.RtdServer.ProgId", "", start)
End Function

Cela marche. J'ai essayé de créer un wrapper C # comme suit:

[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");
    }
}

Lorsque j'entre "= Countdown (150)" dans une cellule dans Excel, il montre la valeur initiale de 150 qui est renvoyée par ConnectData mais jamais des mises à jour. Y a-t-il un rappel que je devrais enregistrer? Suis-je instanciant correctement l'objet d'application? Qu'est-ce que je rate?

Merci,

Franc

Était-ce utile?

La solution

En effet, vous ne vous entraînez pas sur le bon objet d'application. Une solution consiste à implémenter le IdTextensibility2 Interface dans votre complément. Cette interface a une méthode OnConnection que Excel appellera lors du chargement de votre complément. Dans cette méthode, vous êtes passé l'objet d'application que vous pouvez conserver dans une variable locale pour une utilisation ultérieure.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top