views:

15

answers:

1

I need to host Excel spreadsheet in our WinForms app. It looks loading the excel file into WebBrowser control is the way to go. There are several articles on the Internet about this. However, they mostly use Excel 2003 (I guess). Excel 2007 presents some new problems:

  1. By default, the Excel spreadsheet is opened up in a new window, instead of embedded in my WebBrowser control. Base on Microsoft, this is by design, but it also suggests a fix by changing the registry settings. This is not great, but I can probably live with that.

  2. With that registry change, I was able to embed the Excel spreadsheet in my WebBrowser control. However, the Excel Workbook is still open in background - which I can't even close, but is closed automatically when my WinForm app is closed. It is interesting when you watch how the spreadsheet gets loaded: it's loaded into the Excel workbook (in background) first and then transfered into my WebBrowser control. How can I get rid (or hide) of this background window? EDIT: Actually, the Excel window is not closed, but put into background. However, with help from this article at CodeProject, it can be closed. In that article, the Excel window is closed when WinApp is closed. But the same function can be used to close that window on WebBrowser's DocumentCompleted event. It's not perfect becuase you still see a screen flash, but it's okay. I wish there is a better way to do it. To avoid screen flashes, I tried to just minimize the Excel window. However, when I try to set the WindowState to Minimized, it throws a COM exception. Any clue? It would be a better workaround if I could hide this disabled window from beginning.

  3. When you open a spreadsheet first time, a messgebox pops up asking you for options to "Open", "Save", and "Cancel". There is a checkbox to disable it. But I don't want this messagebox ever show up. What is the registry setting for this?

  4. In my spreadsheet, there is an add-in component which should be loaded dynamically. However, loading it to WebBrowser doesn't work (it can't find it). If I make the add-in active, it loads without problem. Is there anything on WebBrowser to be changed to make it work?

Are there better alternatives to host Excel spreadsheet in WinForms app?

A: 

If you have control over the users and what office version they are using you could right click the menu in Visual Studio and add the respective Excel control to the toolbox. You might be able to dynamically load the control as well (which could be a lot more work due to the nuances of each) by checking the registry and error handling.

Mike Cheel
@Mike: Thanks for quick response. Unfortunately, that doesn't seem to be an option for me.
miliu