我有一个包含4列且接近25行的数组。我想知道如何将其导出到Excel工作表。我希望数组中的元素在运行时立即显示在excel表格中。
Dim矩阵(4,25)As String
答案 0 :(得分:0)
假设你想在vb.net中这样做,应该这样做。
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