How to write some data to Excel?
For example like this:
Dim r As Integer = 0, c As Integer = 0
Dim oExcel As Object = Nothing, oWbk As Object = Nothing, oWsh As Object = Nothing, oRng As Object = Nothing
Try
oExcel = CreateObject("Excel.Application")
oWbk = oExcel.Workbooks.Add()
oWsh = oWbk.Worksheets(1)
For c = 0 To 9
For r = 0 To 9
oRng = oWsh.Cells(r + 1, c + 1)
oRng.Value = "Row " & r.ToString & " Column " & c.ToString
Next
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")
Finally
oWsh = Nothing
oWbk = Nothing
If Not oExcel Is Nothing Then oExcel.Visible = True
oExcel = Nothing
End Try
To read Excel file you need to know a file name and worksheet name.
Changing 1 line, you can set oWbk variable to existing Excel file:
oWbk = oExcel.Workbooks.Open(sFileName)
sFileName should be a full path of existing Excel file, for example:
sFileName = "D:\MyFavoritesFiles\example1.xls"