I have an array with 4 columns and close to 25 rows. I want to know how to export it to an excel sheet. I'd like the elements in the array to appear at once inn the excel sheet when run.
Dim matrix(4,25) As String
I have an array with 4 columns and close to 25 rows. I want to know how to export it to an excel sheet. I'd like the elements in the array to appear at once inn the excel sheet when run.
Dim matrix(4,25) As String
Assuming you want to do it in vb.net, this should do it.
Sub Main()
Dim oExcel As Object = CreateObject("Excel.Application")
Dim oBook As Object = oExcel.Workbooks.Open("C:\Book1.xlsx")
Dim oSheet As Object = oBook.Worksheets(1)
Dim matrix(4, 25) As String
Dim i As Integer
Dim j As Integer
'populate matrix
For i = 1 To 4
For j = 1 To 25
matrix(i, j) = i & " " & j
Next j
Next i
'move to excel worksheet
For i = 1 To 4
For j = 1 To 25
oSheet.cells(j, i).Value = matrix(i, j)
Next j
Next i
'Save this Excel document
oBook.SaveAs("C:\Book1.xls", True)
oExcel.Quit()
End Sub