Solved

VB.NET: Can't load Excel (.xlsx) into WebBrowser on Windows Form

Posted on 2013-01-06
5
2,167 Views
Last Modified: 2013-01-07
I have all the references specified for using Excel and WebBrowser (Internet Tools .COM, etc.) and also use the following imports:

Imports Microsoft.Office.Core
Imports Excel = Microsoft.Office.Interop.Excel

Public oDocument As Object

However, after placing a WebBrowser1 on a Windows Form, calling on a file that is e.g. myfile.xlsx, and using the code below, the Webbrowser1 simply shows an info icon, and nothing happens.   Is there something I am missing?   (Note that the msgbox in the NavigateComplete2 never fires).

Also, how can I only show the column and row headers along with the sheet data, thus killing all the Excel menu commands and tools?   (I only want the user to see the gray-colored row and column headers along with the sheet data).  


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  
        Dim filename As String
    
        filename="c:\myfile.xlsx"

        Me.WebBrowser1.Navigate(filename)

End Sub

Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Object)
        MsgBox("NavigateComplete Event")
        On Error Resume Next
        oDocument = pDisp.Document
End Sub

Open in new window

0
Comment
Question by:lep1
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38749951
I assume the real file does actually exist in the path you specify.  
Check it - there are numbers of questions here where it doesn't when a path has been assumed.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
 
        Dim filename As String
   
        filename="c:\myfile.xlsx"
MsgBox(filename)

        Me.WebBrowser1.Navigate(filename)

End Sub


Does the xlsx file actually open in excel when you double click on it from windows explorer ?
0
 

Author Comment

by:lep1
ID: 38750900
Yes, a VBA type of workbook opens with the data. I noticed on a forum that in VB.NET 2010 and newer Office ( I am using 2010 ), that Navigate won't open an Excel.  Rather an activeX control needs to be made.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 100 total points
ID: 38751062
Hmmm.
I've just made a small xlsx file in excel 2007 then typed the path into firefox.  It asks for how to open it (default of excel or browse for an app).  Looks like the forum is 'correct' in that a browser can't open the file natively.
0
 

Author Comment

by:lep1
ID: 38751156
Indeed, most forum posts regarding use of IE to open an Excel in webbrowser are 7-12 years old, and none address Office 2010 and Visual Studio >=2010
0
 

Author Comment

by:lep1
ID: 38751169
Interestingly the worst post claimed that not all your users would be able to open excel in webbrowser via ie due to variation in default sec settings. This is not good for excel and webbrowser
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question