문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top