Introduction
- The core library project can be found on GitHub, where the latest source versions are hosted.
- For general questions and discussion about Excel-DNA, use the Google group or Stack Overflow.
- Specific issues, bug reports and feature requests can be added to the GitHub Issues list.
- For more about Excel-DNA, see the introductory information below, and the searchable (back to February 2007) Google group history.
- For a permanent bookmark to the project, use the Excel-DNA home page at http://excel-dna.net.
Overview
Excel-DNA is an independent project to integrate .NET into Excel. We hope it will be useful to Excel users who currently write VBA code for functions and macros, and would like to start using .NET. Also interested would be C/C++ based .xll add-in developers who want to use the .NET framework to develop their add-ins.
(For a bit more background about .NET and Excel-DNA, see What and why? - An introduction to .NET and Excel-DNA.
The Excel-DNA Runtime is free for all use, and distributed under a permissive open-source license that also allows commercial use.
Excel-DNA is developed using .NET, and users have to install the freely available .NET Framework runtime. The integration is by an Excel Add-In (.xll) that exposes .NET code to Excel. The user code can be in text-based (.dna) script files (C#, Visual Basic or F#), or compiled .NET libraries (.dll). Excel-DNA supports both the .NET runtime version 2.0 (which is used by .NET versions 2.0, 3.0 and 3.5) and version 4. Add-ins can target either version of the runtime, and concurrent loading of both runtime versions into an Excel instance is supported.
Excel versions '97 through 2016 can be targeted with a single add-in. Advanced Excel features are supported, including multi-threaded recalculation (Excel 2007 and later), registration-free RTD servers (Excel 2002 and later) and customized Ribbon interfaces (Excel 2007 and 2010). There is support for integrated Custom Task Panes (Excel 2007 and later), offloading UDF computations to a Windows HPC cluster (Excel 2010 and later), and for the 64-bit versions of Excel 2010 and 2013.
Most managed UDF assemblies developed for Excel Services can be exposed to the Excel client with no modification. (Please contact us if you are interested in this feature)
The latest release - Excel-DNA Latest - includes support for both RTD-based asynchronous worksheet functions (Excel 2002 and later) and native Excel asynchronous functions (Excel 2010 and later). The RTD-based asynchronous support is designed to (optionally) integrate with the .NET 4.0 Task-based operations, as well as the Reactive Extensions library, allowing IObservables to be exposed as 'live' worksheet UDFs - (thus 'RxExcel'). The language-specific support for asynchronous functions in C# 5, Visual Basic 11 and F# 2.0 can be easily integrated with the Excel-DNA asynchronous interfaces.
Are there no other ways to create Excel add-ins with .NET? Why should I use Excel-DNA?
There are a few different ways of making Excel add-ins with .NET, but Excel-DNA has unique advantages. For starters, these are the different kinds of Excel add-ins that can be created with .NET:
- VSTO
- COM add-in
- C API
- Other libraries (e.g. NetOffice, Add-In Express, FCell)
Where does Excel-DNA fit in?
Excel-DNA brings together all three parts that are needed to make a great Excel add-in with .NET - the native Excel C API, the COM object model and the .NET runtime.
Should I not just stick to the official Microsoft tools for making Excel add-ins, rather than relying on a third-party tool?
Using only Microsoft's tools makes it hard to create powerful and full-featured Excel add-ins with .NET that work in different Excel versions, and that are easy to deploy. Some of the problems are:
- Microsoft has no official support for using the native Excel C API in .NET add-ins
- VSTO has no support for making user-defined worksheet functions
- Automation add-ins can provide UDF, but have poor performance, and allow limited customization
- VSTO and regular COM-based add-ins require administrative rights to install
What if I want to make an Excel add-in with Python, C or C++?
Excel-DNA is used for making Excel add-ins with .NET. For alternative programming languages, there are similar libraries that integrate with the native Excel C API, such as:
- Python: PyXLL
- C/C++: Xlw, XLL+
- Modern C++: xll8.
What about VBA? Can Excel-DNA help me use my current VBA skills and still move to .NET?
VB.NET is the newest member of the Visual Basic family. While sometimes overshadowed in popularity by C#, VB.NET is as powerful as C# (sometimes more!), can access all the same .NET libraries, and is fully supported for making Excel-DNA add-ins. Using VB.NET gives a degree of familiar syntax for those who are coming from VBA, requiring a gradual learning curve to get used to the few existing differences. However, rest assured that VB.NET provides access to the full power of .NET and Excel-DNA.
Excel-DNA add-ins can also integrate with VBA code by creating custom COM libraries that can be called from VBA. One advantage in putting these libraries inside an Excel-DNA add-in is that they can be deployed without requiring registration with administrator privileges.
Important Links
The home page for Excel-DNA is at http://www.excel-dna.net.
The documentation is still sparse, but if you need any help, try the main Excel-DNA support forum on Google Groups, https://groups.google.com/group/exceldna, where an extensive history of discussions can be found and searched through.
You are also welcome to contact us with questions, comments or suggestions.
How To's
- Excel-DNA Packing Tool The packing utility allow you to pack your add-in into a single
.xll
file for easy distribution. - Installing your add-in and running generally.
- Accepting Range Parameters in UDFs.
- Integrating with VBA
- Performing Asynchronous Work
- Optional Parameters and Default Values
- Keyboard Shortcut
- Excel Programming Interfaces
- Ribbon Customization and various ribbon links.
- A note on AutoClose and Detecting Excel Shutdown.
- Debugging Notes
- COM Server Support
- Some notes on FSharp Type Inference, and FSharp Standalone Assemblies.
- Asynchronous Functions
- Asynchronous Functions with Tasks example in VB.NET.
- Reactive Extensions for Excel
- Dynamic delegate registration - an advances feature to implement runtime registration and function wrappers.
- User settings and the .xll.config file
- A step-by-step guide to build a new add-in using the NuGet package, and then Configure NLog logging for your add-in.
- Creating a help file
- Returning 1-D Arrays
- Async macro example - formatting the calling cell from a UDF
- Enumerating Excel COM Automation collections in VB.NET
- Modal dialog on new thread
- Utilizing custom XML parts in Excel Workbooks
- Checking for updates and download of Excel-DNA Addins (or other .NET based programs)
Samples
Various sample projects and snippets related to Excel-DNA are available in the Samples repository.
Excel-DNA Extension Projects
- ExcelDnaDoc provides tools to make help generation easier.
- Registration allows the automatic generation of parameter and function conversions, removing boiler-plate code for optional parameters, async functions etc.
- IntelliSense add in-sheet IntelliSense for Excel UDFs.
Community Projects
- ExcelDna-Unpack is a command-line utility to extract the contents of Excel-DNA add-ins packed with ExcelDnaPack
- ExcelDna.Abstractions facilitates mocking & unit testing of Excel-DNA Add-Ins
- ExcelDna.WiXInstaller is a user-contributed template (thank you very much to Lee Zeitz!) for making a WiX-based installer for an Excel-DNA add-in.
- ExcelDna.StrongName provides strong name key pair used to sign Excel-DNA assemblies.
- ExcelDna.Diagnostics.Serilog integrates Excel-DNA Diagnostic Logging with your Serilog logging pipeling within your Excel-DNA Add-In
- Serilog.Sinks.ExcelDnaLogDisplay is a Serilog sink that writes events to Excel-DNA LogDisplay
- Serilog.Enrichers.ExcelDna is a Serilog Enricher with properties from Excel-DNA Add-Ins
External Links
If you are a VBA developer interested in moving to .NET, you should start with Patrick O'Beirne's detailed VBA to Excel-DNA migration guide.
Various Samples and Tutorials
- Hugo Diz - TextUtilsDNA is a useful text processing add-in, and also a nice example add-in created with VB.NET.
- As a comprehensive example using many of the Excel-DNA features, be inspired by the Financial Analytics Suite (FinAnSu), an open-source C# add-in built by Bryan McKelvey.
- Ross McLean has a series of posts on getting started with Excel-DNA.
- Mikael Katajamäki shows how to use Microsoft Solver Foundation to build a curve fitting function for Excel
- Mikael Katajamäki shows how to use C++/CLI code as a wrapper class for native (Quantlib based) C++ code and interfaced the C# client code to Excel by using Excel-DNA
- Simon Murphy - xlls with Excel-DNA
- Ed Parcell - Numerical analysis in Excel using C# with Excel-DNA and AlgLib
- Mathias Brandewinder - Mutant Excel with .NET and Excel-DNA
- Mathias Brandewinder - Supercharge Excel functions with Excel-DNA and .NET parallelism
- Mike Woodhouse - A third way: DNA?
- Patrick O'Beirne - From VBA to VB.NET using Excel-DNA
- Doctor Torsten - Bring Excel 2010 to Speed: Remote UDFs with Excel 2010 and HPC Server 2008 R2
- Luca Bolognese - A trading/portfolio management Excel Add-in based on the books by Ralph Vince
- Supermab's series of blog posts introducing Excel-DNA to Japan (in Japanese)
- Joao Morais - WCF client sample
- teramonagi - Using R from Excel using Excel-DNA (Also check out the F# R type provider.)
- Gert-Jan van der Kamp - Streaming real-time data to Excel
- Eddie Gahan - TransposeBy - Extending Excel With C# And Excel-DNA
Various F# Examples
- a wrapper for the ExcelReference type and C API with some cell access features,
- an object handle wrapper, and
- a WPF-based Custom Task Pane for Excel.
- Three samples, including a function using the R type provider by Natallie Baikevich.
- Bram Jochems has published a wonderful collection of finance-related functions on GitHub, as well as some details on creating a ribbon menu with F#.
- Useful Range wrappers by Kit Eason: Higher-Order Functions for Excel.
External projects using Excel-DNA
Dodoni.net is a free/open-source library for quantitative finance and numerical computing..
Cubicle Tools is a collection of tools that extends Excel for analytical and rapid development purposes. It includes an object handler and an add-in distribution system.
EQ Finance - Analytics library for derivatives pricing and risk management
Technoscience UK has some interesting add-ins to mirror Excel data between PCs.
compute!box! allows real-time interchange of data between spreadsheets (via Azure Service Bus).
This Office icon gallery has an Excel-based viewer.
Jon Nyman's FxToExcel add-in brings financial program data into Excel.
Stock Quote Add-In for Excel provides access to the Yahoo financial data through an Excel-DNA add-in.
DB-Addin for Excel is an MS Excel Addin for retrieving Database data via userdefined functions into Excel and writing Data (DBMapper), executing generic DML (DBAction) and doing all this in Sequences (DBSequence).
Datepicker is a replacement for the MSCOMCT2 based Datepicker that Microsoft abandoned in 64bit versions of Excel. It passes the .NET MonthCalendar widget to VBA Userforms.
Alex Chirokov's ACQ add-in provides a library of interpolation routines for Excel. The add-in includes 1D and 2D interpolators, scatter plot smoothing and a Mersenne Twister random number generator. To have a closer look:
- Find the current release on GitHub: https://github.com/ratesquant/ACQ/releases
- With the main repository on GitHub at https://github.com/ratesquant/ACQ
- A very clear introduction to the library, including some of it's advanced features, is posted on Code Project: http://www.codeproject.com/Articles/1097174/Interpolation-in-Excel-using-Excel-DNA Features I like about the add-in (apart from it using Excel-DNA) include:
- A liberal open-source license
- A clear and authoritative implementation of a particular domain
- Very nice example of using object handles - an interpolator is build from the data, and then used to interpolate many values. ACQ has a clean implementation and great example of this technique.
- All the functions have a common prefix ("
=acq
..."), making them easy to find in the function list, and use with the Excel-DNA IntelliSense extension. - PS: ACQ has a bonus feature that implements a Sudoku solver (and generator)! See the write-up here: Sudoku Solver in Excel using C# and Excel-DNA.
I noticed a very nice add-in developed by Bryan McKelvey called FinAnSu. The whole add-in is generously available under the MIT open source license, and is a fantastic example of what can be built with Excel-DNA.
FinAnSu uses a ribbon interface to make the various functions and macros easy to find. The RTD server support is used to implement asynchronous data update functions, providing a live quote feed from Bloomberg, Google or Yahoo! And then there is a bunch of useful-looking financial functions. Here's a little preview:
- Find the project on GitHub: https://github.com/brymck/finansu, with detailed documentation.
- You can browse through the source code online, and you can also download a copy of the whole project.
Support
There is a searchable record of more than 5000 messages on the Excel-DNA Google Group.
There are many questions answered on Stack Overflow under the tag excel-dna
.
Please don't hesitate to ask. If you are stuck or need some help using Excel-DNA your questions really are very welcome - whether you are just getting started, or an Excel-DNA expert.
And if you could help put together some proper documentation, please contact me. We'd be happy to add you as an editor in this repository.
Related Projects
- NetOffice is a set of version-independent assemblies to allow Office integration through the COM automation interface. The NetOffice libraries can be used from an Excel-DNA add-in to ease version-independent Excel add-in development, and ease compatibility with VBA.
- Visual Studio Tools for Office (VSTO) is Microsoft's preferred plan for integrating .NET with Office. It is mainly aimed at making it easy for Visual Studio developers to create solutions integrated with the Office applications. In contrast, Excel-DNA is (eventually) aimed at Excel end-users, as a compelling replacement for VBA, completely independent of Visual Studio.
- Add-in Express is a commercial alternative to VSTO for users with Visual Studio. It support making add-ins for the various Office products, not just Excel, and has helpful wizards and graphics designers.
- Jens Thiel's ManagedXll was an established, commercial product to easily create .xll libraries in .NET. If ManagedXll were free, Excel-DNA would not exist.
- Statfactory's NeXL are F# based connectors to get data from various platforms (Bloomberg, Quandl, Worldbank, IMF and the R language) into Excel.
- For making Excel Add-Ins in Python, have a look at PyXLL.
- There are a number of C/C++ libraries and tools that make creating .xlls easier than using the Excel SDK directly:
- I initially used the XLW open-source library.
- The XLL+ toolkit is a highly regarded commercial option.
- Keith Lewis has some modern C++ libraries for making .xlls, available on CodePlex at https://archive.codeplex.com/?p=xll.
Performance
Information about the performance of Excel-DNA user-defined functions can be found on the Excel-DNA Performance page.
More Details
Excel-DNA is developed using .NET, and users have to install the freely available .NET Framework runtime. The integration is by an Excel Add-In (.xll) that exposes .NET code to Excel. The user code can be in text-based (.dna) script files (C#, Visual Basic or F#), or compiled .NET libraries (.dll). Excel-DNA supports both the .NET runtime version 2.0 (which is used by .NET versions 2.0, 3.0 and 3.5) and version 4. Add-ins can target either version of the runtime, and concurrent loading of both runtime versions into an Excel instance is supported.
Excel versions '97 through 2016 can be targeted with a single add-in. Advanced Excel features are supported, including multi-threaded recalculation (Excel 2007 and later), registration-free RTD servers (Excel 2002 and later) and customized Ribbon interfaces (Excel 2007 and 2010). There is support for integrated Custom Task Panes (Excel 2007 and later), offloading UDF computations to a Windows HPC cluster (Excel 2010 and later), and for the 64-bit versions of Excel 2010 and 2013.
Most managed UDF assemblies developed for Excel Services can be exposed to the Excel client with no modification. (Please contact me if you are interested in this feature.)
Since Excel-DNA uses the Excel C API, porting C/C++ add-in code based on the Excel XLL SDK is very easy. (No more XLOPER
s!)
The Excel-DNA Runtime is free for all use, and distributed under a permissive open-source license that also allows commercial use.
Originally, the project was hosted on https://exceldna.codeplex.com, where you can still download the site in it's historic state as a package. After CodePlex' shutdown the archive site is however mostly unusable by now.
Latest Releases
The current version on NuGet is Excel-DNA Latest, released in October 2022.
Topics to Discuss Further
- Migrating to .NET 6 from .NET 4
- Excel-DNA Project Templates
- Comparison with other tools