質問

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