I have excel with the Bloomberg API ( which uses simple calls like =BDP("MS equity","ask") ). I also have a C# application that opens an excel file (through interop) that uses the Bloomberg API. I have read here that addins are not loaded when you load excel through interop. I have even tried using the code suggested there. However, that only seems to work for XLL and XLAM files and it looks like Bloomberg also uses DLL files which doesn't get loaded. Is there any way to get all of these addins to be loaded through interop?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
I assume that, if you start excel manually the add-ins are loaded properly.
If so, you can get an Excel Interop Object with loaded BB-Addins by calling
Process p = Process.Start("excel.exe");
and then using theAccessibleObjectFromWindow
method to get the Interop Object.An example on how to do that can be found here.
Quick walkthrough
I decided to show the steps I went through to get an
Excel.Interop.Application
instance with loaded bloomberg add ins. Maybe someone looks at this and finds it useful, or knows where I missed something to get a more elegant solution.The simplest way doesn't work
Run()
will throw aCOMException
:Loading AddIns by hand doesn't work
But if start Excel by klicking on the Windows Taskbar, the AddIns are being loaded nicely... So I tried to start excel by starting the executable file "excel.exe".
Using Process.Start("excel.exe") works!!
Starting excel using the
System.Diagnostics.Process
class loads the bloomberg AddIns. (I can see theBloomberg-RibbonTab
.)Now all I need is the Interop-Object of that excel process. I can get it using the above example
My implementation of it
Now I can use the following line of code to get an
Excel.Interop.Application
instance with loaded bloomberg addins!I hope this spares someone the hours I wasted with this and if someone has a more elegant solution and wants to share it, it would be much appreciated.
If you want to load a DLL into Excel addins, you must register this DLL file using RegAsm. And check
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Excel\AddIns
to see whether it's registered successfully.I was able to get a similar result using NetOffice. This particular function will retrieve the last started instance of the excel process or create a new one if one does exist. From there you are free to open/create a new workbook.
The nice thing about using netoffice and this approach is that it doesn't depend on version specific interop DLLs and if you dispose of the NetOffice objects then all of the excel COM objects are cleaned up properly.
Usage:
I realize that it's been while since this question has been asked. Nevertheless I want to share my experience as I came across the same problem. An easy solution is to proceed as suggested in https://blogs.msdn.microsoft.com/accelerating_things/2010/09/16/loading-excel-add-ins-at-runtime/ by first setting .Installed to false and then to true: