我正在使用以下代码将 Excel 工作表加载到 Windows 窗体上的 WebBrowser 控件中,并且导航中的 msgbox 会触发,但工作表在 WebBrowser 中不可见。此外, Navigated2 也无济于事。有什么东西不见了吗?
仅供参考:正在声明对项目的以下引用:
Microsoft Office 14.0 Object Library
Microsoft Excel 14.0 Object Library
Microsoft Internet Controls
Microsoft Common Dialog Control 6.0 (SP6)
Imports Office = Microsoft.Office.Core
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim oDocument As Object
Private xlAPP As New Excel.Application
Private xlWBook As Excel.Workbook
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' Create new Application.
Dim filename As String = Nothing
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = True
.Filter = "Excel files *.xlsx|*.xlsx"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
'Load file
filename = .FileName
End If
End With
With xlAPP
.Visible = False
xlWBook = .Workbooks.Open(filename)
xlWBook.Activate()
End With
Me.WebBrowser1.Navigate(xlWBook.FullName)
End Sub
Private Sub WebBrowser1_Navigated(ByVal pDisp As Object, URL As Object) Handles WebBrowser1.Navigated
MsgBox("NavigateComplete Event")
On Error Resume Next
oDocument = pDisp.Document
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
With xlAPP.CommandBars("Standard")
.Visible = True
End With
End Sub
End Class