0
我有一個VB.NET與.NET 4.5中的窗體。 我有一個EXCEL文件並排打開窗體。從VB.NET Excel表格中的實時更新數據表格
我想在EXCEL工作表中看到來自代碼LIVE的更新數據。 但不能看到數據。
下面是代碼
Imports Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Me.OpenFileDialog1.ShowDialog()
Dim xlApp As Application
Dim xlWorkBook As Workbook
Dim xlWorkSheet As Worksheet
xlApp = New ApplicationClass
'xlApp.ScreenUpdating = False
xlWorkBook = xlApp.Workbooks.Open("E:\BACKUP\TRY.xls")
xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
'display the cells value B2
MsgBox(xlWorkSheet.Cells(8, 1).value) 'GETTING EXISTING VALUE OK
'edit the cell with new value
xlWorkSheet.Cells(2, 2) = "HI" 'WANT TO SEE THIS DATA BEING LIVE UPDATED
'xlWorkBook.Close() 'DONT WANT TO CLOSE THE OPENED SHEET/WORKBOOK
'xlApp.ScreenUpdating = True
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
End Class