Updated April 2020
Excel does support getting real time data into the worksheet with the RTD function, but this requires programming a COM server with which the RTD function communicates.
Power BI is able to make use of streaming data via API connections or PubNub, but what if I just want to pull some live data directly into a cell?
With PyXLL I can do just that. PyXLL is an add-in that allows you to write Python code and use the results in Excel. Not only can you pull in real time data, you can write your own functions, amongst other things, making use of the many Python libraries available.
PyXLL uses a class derived from RTD which when combined with your own Python code, allows you to stream real time data.
Before You Start
You will of course need an installation of Python on your PC that will be used by PyXLL in Excel. Download and install the latest version from here : Get Python - it's free!
Once that's done you can get PyXLL from here : PyXLL, which is available for a 30 day free trial, after that there is a charge for continuing to use it.
Real Time Data
The world is awash with mentions of IoT (Internet of Things) streaming data from devices like sensors that tell you the temperature of the water in your fish tank, to what your cows are doing.
If you had a stream of data from an IoT device you could certainly use the following method to read and present the data in Excel. But in this post I'm going to write code for two examples, the price of crypto currencies, and some random numbers from a web based random number generator.
To get such information it can be made available by what's known as an API - application programming interface. Which is a way of asking for and getting some data from a program, website or some other similar service.
For the crypto currencies, CoinCap provide a simple API which gives you information including the price for the currency you specify.
If I want to get the price of Bitcoin all I need to do is visit https://api.coincap.io/v2/assets/bitcoin
If you click that link, rather than see a nicely laid out website, you'll just see a bunch of text like this
That's because the website is expecting to be sending the data back to a program so has formatted it into a JSON response the program can easily use. This is not meant for human eyes so isn't meant to look pretty. When we get this data we manipulate it in our Python code and return whatever we want to Excel, which in this case is the price.
If you want to you could make use of all the other information too but I just want the price for this example.
So by making a call to the CoinCap API for each currency I specify, it sends me the informaton related to that crypto currency.
It works the same way for the random number generator. My Python code makes a call to the random number generator at https://random.org, and the website sends me back a random integer.
PyXLL RTD Class
By adding this RTD class into your code and modifying __thread_func to do the work of calling the API's and processing the result, we get our code to update our currency prices and random numbers in real time.
Crypto Currency Price Updates
Random Number Generator
Calling the Functions
By defining a function for both of these bits of code through PyXLL, Excel is able to access them like it would any other workbook function.
To get the price for Bitcoin
Note that the currency name must be lower case.
You can pass in a cell reference rather than a string if you want to e.g.
Where A1 contains the currency name.
For the random numbers, use this next function which doesn't require any arguments
Here are both functions in action.
I'm multiplying the random numbers by a decimal to make them more interesting, and I've added some conditional formatting to make the numbers visually appealing.
The top 50% of the currencies by price are green, the bottom 50% are red. In the workbook you can download just below, I've included just 3 currencies, but I'm sure you can add any others you want.
For the random numbers, any number greater than the average of all the numbers, is green.
Download the Excel Workbook and Python Code
In order to get this to work you'll need an installation of Python and to have installed the PyXLL add-in as described at the top of this article.
My workbook and sample Python code are provided for download as a ZIP file. Enter your email address below to get these.
If you know Python or want to try your hand at it, PyXLL is definitely worth a look. And if you want to get real time data into Excel it looks like a good solution.