Question

I have written an RTD server that I wrap in a UDF - both in C# which looks like this:

public object MyUDF(string ItemID, string TopicName)
{
    return _xlApp.WorksheetFunction.RTD("my_rtdserver", null, TopicID, TopicName);
}

The UDF delivers string, date and numeric data but it all seems to be formatted as strings which doesn't allow me to work with numeric data with excel formulas such as SUM(A:A).

I have tried to format the numeric cells with "Number" format but this doesn't make any difference.

Anyone have this problem?

Cheers

Was it helpful?

Solution

I have found the following to work:

public object MyUDF(string TopicID, string TopicName)
{
    var value = _xlApp.WorksheetFunction.RTD("my_rtdserver", null, TopicID, TopicName);
    double num;
    if (!double.TryParse(value, out num))
        return value;
    return num;
}

See: Checking if an object is a number in C#

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top