Excel 2016 RTD界面 [英] Excel 2016 RTD interface

查看:76
本文介绍了Excel 2016 RTD界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他版本相比,IRTDServer接口中对ServerStart / ServerTerminate的调用在Excel 2016中的行为似乎有所不同。

Calls to ServerStart / ServerTerminate  in the IRTDServer interface seem to behave differently in Excel 2016 when compared to other versions.

请试试这个:

---------------------

---------------------




推荐答案

您好Asgard,

Hi Asgard,

由于我无法在Excel 2016中测试,我正在尝试在Excel 2016预览中重现此问题。  ;但它失败了。

Since I am not able to test in Excel 2016, I am trying to reproduce this issue in Excel 2016 preview. However it is failed.

代码适用于我,这是我在第一个工作簿中调用RTD函数的日志,然后创建一个新工作簿并在新工作簿中调用该函数:

The code works well for me, here is the logs which I call the RTD functions in the first workbook, then create a new workbook and call the function in new workbook:

37:01: ServerStart...
37:01: ConnectData...
37:06: timerUpdate...
37:06: RefreshData...
The thread 0x47d4 has exited with code 0 (0x0).
The thread 0x33d8 has exited with code 0 (0x0).
The thread 0x3b40 has exited with code 0 (0x0).
37:16: timerUpdate...
37:16: RefreshData...
37:26: timerUpdate...
37:26: RefreshData...
The thread 0x25e8 has exited with code 0 (0x0).
37:36: timerUpdate...
37:36: RefreshData...
37:46: timerUpdate...
37:46: RefreshData...

以下是我测试的参考代码:

Here is code that I tested for your reference:

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using XL = Microsoft.Office.Interop.Excel;

namespace alignmentsystems.n2excel
{

    [ComVisible(true)]
    [ProgId("alignmentsystems.n2RTD")]
    public class n2RTD : XL.IRtdServer
    {
        private readonly Dictionary<int, IncrementUpwards> _topics = new Dictionary<int, IncrementUpwards>();
        private Timer _timer;

        XL.IRTDUpdateEvent _CallbackObject;

        public int ServerStart(XL.IRTDUpdateEvent CallbackObject)
        {
            Debug.Print(String.Format("{0:mm:ss}: ServerStart...", DateTime.Now));
            _CallbackObject = CallbackObject;
            _timer = new Timer(delegate { timerUpdate(); }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
            return 1;
        }

        public void ServerTerminate()
        {
            Debug.Print(String.Format("{0:mm:ss}: ServerTerminate...", DateTime.Now));
            _timer.Dispose();
        }

        public void timerUpdate()
        {
            Debug.Print(String.Format("{0:mm:ss}: timerUpdate...", DateTime.Now));
            _CallbackObject.UpdateNotify();
        }

        public dynamic ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
        {
            Debug.Print(String.Format("{0:mm:ss}: ConnectData...", DateTime.Now));
            var start = Convert.ToInt32(Strings.GetValue(0).ToString());
            GetNewValues = true;
            _topics[TopicID] = new IncrementUpwards { CurrentValue = start };
            return start;
        }

        public void DisconnectData(int TopicID)
        {
            Debug.Print(String.Format("{0:mm:ss}: DisconnectData...", DateTime.Now));
            _topics.Remove(TopicID);
        }

        public int Heartbeat()
        {
            return 1;
        }

        public Array RefreshData(ref int TopicCount)
        {
            Debug.Print(String.Format("{0:mm:ss}: RefreshData...", DateTime.Now));
            var data = new object[2, _topics.Count];
            var index = 0;

            foreach (var entry in _topics)
            {
                ++entry.Value.CurrentValue;
                data[0, index] = entry.Key;
                data[1, index] = entry.Value.CurrentValue;
                ++index;
            }
            TopicCount = _topics.Count;
            return data;
        }

    }

    public class IncrementUpwards
    {
        public int CurrentValue { get; set; }
    }

}

我会在环境建立时在Excel 2016中测试此问题。如果我有任何更新,我会回来。

I would test this issue in Excel 2016 when the environment is build up. And I would be back if I have got any update.

问候& Fei

Regards & Fei





这篇关于Excel 2016 RTD界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆