views:

271

answers:

3

Fairly straightforward scenario, for which I can't seem to find an answer anywhere:

  • I am using a Microsoft WebBrowser ActiveX control (AxSHDocVw.AxWebBrowser) in a Windows Forms application.
  • The WebBrowser control is used to display Excel workbooks in the application.
  • I can obtain a reference to the internal document as a Microsoft.Office.Interop.Excel.Workbook.
  • What I cannot seem to find, despite hours of searching the Web, is any reliable guidance on how to determine the range of cells currently selected by the end-user.

Here's the problem. Since the sheet is displayed in the browser, it doesn't have the Excel toolbar displayed, and I'd like to provide at least some rudimentary functionality (cut, copy, paste, undo, redo, bold, italic, underscore, left, right, center, and so on) from my application's main window. In order to do that, I need to be able to forward those commands onto the active sheet. Some of those commands require knowledge of the currently selected range if I want to properly execute them.

If anyone knows how to do this, I would be forever in your debt. (Well, maybe not forever, but you get the point.)

[NOTE: I use the old ActiveX control so that I can trap the NavigateComplete2 event to capture the reference to the internal document. The .NET WebBrowser control doesn't expose this functionality the same way.]

+1  A: 

If you can get the workbook reference, you should be able to do .Application.Selection to get the current selected Range.

nitzmahone
A: 

SpreadsheetGear for .NET includes an Excel compatible Windows Forms control which you might find easier to use in your .NET applications.

You can download a free trial here.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
Alas, I've seen your component, and it's price. It's WAY out of my price range. :(
Mike Hofer
A: 

Check using the following code....

if (wkbk.Application.Selection != null)
{
   if (wkbk.Application.Selection is Excel.Range)
   {
      //your code to obtain an Excel.range object goes here...
   }
}
Anonymous Type