-1

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

2

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.