我正在使用以下代码在 VB.net 2010 Express 的 WebBrowser 控件中显示 Excel 电子表格。
Option Explicit On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Core
Imports System.Data
Public Class CustomerService
Dim oDocument As Object
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Private Sub CustomerService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(quoteFile)
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles WebBrowser1.NavigateComplete2
On Error Resume Next
Dim oXL As New Excel.Application
oDocument = e.pDisp.Document
With oDocument.Application.CommandBars("Standard")
.Position = 4 '[msoBarFloating]
.Visible = True
End With
MsgBox("File opened by: " & oDocument.Application.Name)
oDocument.Range("A1") = "HEllo"
End Sub
End Class
我的问题是,如何在 WebBrowser1_NavigateComplete2 方法中引用打开的文档,以便我可以自动化 excel 在特定单元格中显示文本。
试过:
Option Explicit On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Core
Imports System.Data
Public Class CustomerService
Dim oDocument As Object
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Private Sub CustomerService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(quoteFile)
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles WebBrowser1.NavigateComplete2
On Error Resume Next
Dim oXL As New Excel.Application
oDocument = e.pDisp.Document
objApp = oDocument
objBooks = objApp.Workbooks
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(1)
oXL = oDocument(.Document) 'with or without .Document
With oDocument.Application.CommandBars("Standard")
.Position = 4 '[msoBarFloating]
.Visible = True
End With
MsgBox("File opened by: " & oDocument.Application.Name)
objSheet.Range("A1") = "HEllo"
End Sub
End Class
没有运气。如果你甚至有办法接受这个,我会全神贯注。
谢谢