VB怎么将数组的数据保存到Excel中?
展开全部
给你个高速两维数组的参考一下
你改改就是
Dim aa(300, 200) As Double
Private Sub Command1_Click()
Dim XlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Range(xlSheet.Cells(LBound(aa, 1) + 1, LBound(aa, 2) + 1), xlSheet.Cells(UBound(aa, 1) + 1, UBound(aa, 2) + 1)).Value = aa
Erase aa '要释放数组,免得占用内存
End Sub
Private Sub Form_Load()
For i = LBound(aa, 1) To UBound(aa, 1)
For j = LBound(aa, 2) To UBound(aa, 2)
aa(i, j) = i + j
Next
Next i
End Sub
你改改就是
Dim aa(300, 200) As Double
Private Sub Command1_Click()
Dim XlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Range(xlSheet.Cells(LBound(aa, 1) + 1, LBound(aa, 2) + 1), xlSheet.Cells(UBound(aa, 1) + 1, UBound(aa, 2) + 1)).Value = aa
Erase aa '要释放数组,免得占用内存
End Sub
Private Sub Form_Load()
For i = LBound(aa, 1) To UBound(aa, 1)
For j = LBound(aa, 2) To UBound(aa, 2)
aa(i, j) = i + j
Next
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |