Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4338220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:03:08+00:00 2026-05-21T11:03:08+00:00

I was tasked with writing a real-time Excel automation add-in in C# using RtdServer

  • 0

I was tasked with writing a real-time Excel automation add-in in C# using RtdServer for work. I relied heavily on the knowledge that I came across in Stack Overflow. I have decide to express my thanks by writing up a how to document that ties together all that I have learned. Kenny Kerr’s Excel RTD Servers: Minimal C# Implementation article helped me get started. I found comments by Mike Rosenblum and Govert especially helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:03:10+00:00Added an answer on May 21, 2026 at 11:03 am

    (As an alternative to the approach described below you should consider using Excel-DNA. Excel-DNA allows you to build a registration-free RTD server. COM registration requires administrative privileges which may lead to installation headaches. That being said, the code below works fine.)

    To create a real-time Excel automation add-in in C# using RtdServer:

    1) Create a C# class library project in Visual Studio and enter the following:

    using System;
    using System.Threading;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using Microsoft.Office.Interop.Excel;
    
    namespace StackOverflow
    {
        public class Countdown
        {
            public int CurrentValue { get; set; }
        }
    
        [Guid("EBD9B4A9-3E17-45F0-A1C9-E134043923D3")]
        [ProgId("StackOverflow.RtdServer.ProgId")]
        public class RtdServer : IRtdServer
        {
            private readonly Dictionary<int, Countdown> _topics = new Dictionary<int, Countdown>();
            private Timer _timer;
    
            public int ServerStart(IRTDUpdateEvent rtdUpdateEvent)
            {
                _timer = new Timer(delegate { rtdUpdateEvent.UpdateNotify(); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
                return 1;
            }
    
            public object ConnectData(int topicId, ref Array strings, ref bool getNewValues)
            {
                var start = Convert.ToInt32(strings.GetValue(0).ToString());
                getNewValues = true;
    
                _topics[topicId] = new Countdown { CurrentValue = start };
    
                return start;
            }
    
            public Array RefreshData(ref int topicCount)
            {
                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 void DisconnectData(int topicId)
            {
                _topics.Remove(topicId);
            }
    
            public int Heartbeat() { return 1; }
    
            public void ServerTerminate() { _timer.Dispose(); }
    
            [ComRegisterFunctionAttribute]
            public static void RegisterFunction(Type t)
            {
                Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
                var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\InprocServer32", true);
                if (key != null)
                    key.SetValue("", System.Environment.SystemDirectory + @"\mscoree.dll", Microsoft.Win32.RegistryValueKind.String);
            }
    
            [ComUnregisterFunctionAttribute]
            public static void UnregisterFunction(Type t)
            {
                Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
            }
        }
    }
    

    2) Right click on the project and Add > New Item… > Installer Class. Switch to code view and enter the following:

    using System.Collections;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    namespace StackOverflow
    {
        [RunInstaller(true)]
        public partial class RtdServerInstaller : System.Configuration.Install.Installer
        {
            public RtdServerInstaller()
            {
                InitializeComponent();
            }
    
            [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
            public override void Commit(IDictionary savedState)
            {
                base.Commit(savedState);
    
                var registrationServices = new RegistrationServices();
                if (registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
                    Trace.TraceInformation("Types registered successfully");
                else
                    Trace.TraceError("Unable to register types");
            }
    
            [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
            public override void Install(IDictionary stateSaver)
            {
                base.Install(stateSaver);
    
                var registrationServices = new RegistrationServices();
                if (registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
                    Trace.TraceInformation("Types registered successfully");
                else
                    Trace.TraceError("Unable to register types");
            }
    
            public override void Uninstall(IDictionary savedState)
            {
                var registrationServices = new RegistrationServices();
                if (registrationServices.UnregisterAssembly(GetType().Assembly))
                    Trace.TraceInformation("Types unregistered successfully");
                else
                    Trace.TraceError("Unable to unregister types");
    
                base.Uninstall(savedState);
            }
        }
    }
    

    3) Right click on the project Properties and check off the following: Application > Assembly Information… > Make assembly COM-Visible and Build > Register for COM Interop

    3.1) Right click on the project Add Reference… > .NET tab > Microsoft.Office.Interop.Excel

    4) Build Solution (F6)

    5) Run Excel. Go to Excel Options > Add-Ins > Manage Excel Add-Ins > Automation and select “StackOverflow.RtdServer”

    6) Enter “=RTD(“StackOverflow.RtdServer.ProgId”,,200)” into a cell.

    7) Cross your fingers and hope that it works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been tasked with writing a monitoring program for my company's server software that
I'm tasked with writing a solution for fixing a poorly performing legacy excel file
I have been tasked with writing an ADP application using Access. The back-end data
I am tasked with writing an authentication component for an open source JAVA app.
I've been tasked with the the maintenance of a nonprofit website that recently fell
I've been tasked with fixing an old VSS database. At this point in time,
I am tasked with writing unit tests for a suite of networked software written
I'm tasked with writing a web pseudo-crawler to calculate certain statistics. I need to
I have been tasked with writing an installer with a silverlight out of browser
I've been tasked with writing a SOAP web-service in .Net to be middleware between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.