In the previous post I showed how an existing set of UDFs, defined in an Excel addin, can be used with Excel Services by wrapping them with a managed UDF assembly.
Some companies develop calculation libraries in a modular way. They want to use their library functions for various purposes on various platforms, and Excel UDFs is just one of those purposes. So they develop a function library, say in C or C++, which is independent of any of those platforms, and does not assume any application-specific interface. Then, to use the function library with Excel, they wrap it with an Excel addin, typically an XLL.
If you have such a solution, and now you wish to extend it to Excel Services as well, then all you need to do is develop the extra managed wrapper for the serer side. Since you already have a core function library, you donât need to mess with wrapping an XLL; you can wrap your core library directly, and in many cases you can even embed it within the managed DLL â making server deployment much easier.
Letâs see how this is done.
âWish Excel Hadâ â version 3
Letâs (ab)use the âWish Excel Hadâ code sample from the previous posts once again. This time, the sample I am attaching is based on a core C++ library, which implements the static Word and Wordcount methods in a simple C++ class. Here is the sample code, and here is a workbook to use with the code.
You will find an XLL addin, that wraps those two C++ methods with UDFs for Excel client â WehWord and WehWordcount. In addition, you will find a managed UDF assembly, implemented in C++/CLI (âManaged C++â), which exposes the same two functions as managed UDFs for Excel Services. This time, the wrapper is much simpler; it does not have to deal with mapping .NET types to Excelâs specific interface. E.g. it does not deal with byte-count strings, it does not need to parse XLOPER structures and isolate error cases, and it does not need to handle the XLL way of allocating and releasing memory.
In this sample, the UDF assembly DLL actually embeds the core native function library, so all you need to deploy to the server is this single DLL.
More Excel Services UDF documentation, tips and tricks
â¢ Shahar Prish has lots of good stuff in his blog. He is a distinguished member of the Excel Services developer team, and he really knows what heâs talking about (he actually implemented much of this). Very good reading material. Look under the Excel Services category.
â¢ Office 2007 Beta program participants can find the Office SharePoint Server 2007 SDK documentation on the beta web site. The SDK covers the development of UDFs for Excel Services.