Problem in running Excel-embeded .Net application
Following Microsoft KB (http://support.microsoft.com/kb/304662) instruction, it is easy to embed an excel workbook (spreadsheet) in a .Net Winform program.
The real problem arises when there is a stand-along Excel application already running before launching an Excel-embedded Winform. The stand-along Excel application will hang up. It is believed that the Winform will take control of the external Excel instance. If more than one stand-along Excel instances are running, then the first one will be taken over by this Winform.
All Visual studio .Net versions have the same problem. Microsoft just totally ignored this obvious issue. Does anyone have a good idea on this problem? We have a not-so-elegant workaround for it. But I am looking for a better solution. Thanks very much for your help.
Krishnaraj LPosted Mar 5, 2007, 10:43 AM
Friend,
I have not tried this in C#. But i was able to solve this in C++. From Office 97 onwards, microsoft has maintained a single instance for office application, but when you try to create it using automation(by embedding it), it will create a new instance. Now we have ROT (Running objects table) that tracks the instance of objects. So, before creating a new instance, you will have to always query in ROT and use the an instance if it is already running.
Search for GetActiveObject function in MSDN. We may have to try something like this in C# as well. I will try this and let you know.