主题:求助,关于EXCEL输出的问题,急
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet(1 To 5) As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
xlApp.Visible = True
For i = 1 To 1
Set xlSheet(i) = Excel.Worksheets.Add
xlSheet(i).Name = "表" & i
For k = 0 To DataGrid1(i).Columns.Count - 1
xlSheet(i).Cells(1, k + 1) = DataGrid1(i).Columns(k).Caption
Next
For o = 0 To DataGrid1(i).ApproxCount - 1
For j = 0 To DataGrid1(i).Columns.Count - 1
DataGrid1(i).Col = j
xlSheet(i).Cells(o + 2, j + 1) = DataGrid1(i).Text
Next
If o < DataGrid1(i).ApproxCount - 1 Then
DataGrid1(i).Row = DataGrid1(i).Row + 1
End If
Next
Me.MousePointer = 0
Set xlSheet(i) = Nothing
Next i
Set xlApp = Nothing
Set xlBook = Nothing
End Sub
以上代码哪里错了吗?怎么只能输出一次?
进程为何关不掉?请高手解答或修改下代码,谢谢了. \\
\
问题补充:我这里说的只能输出一次,是指每次打开应用程序只能成功输出一份表,然后必须将表格进程关掉,再打开应用程序才能再次输出
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet(1 To 5) As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
xlApp.Visible = True
For i = 1 To 1
Set xlSheet(i) = Excel.Worksheets.Add
xlSheet(i).Name = "表" & i
For k = 0 To DataGrid1(i).Columns.Count - 1
xlSheet(i).Cells(1, k + 1) = DataGrid1(i).Columns(k).Caption
Next
For o = 0 To DataGrid1(i).ApproxCount - 1
For j = 0 To DataGrid1(i).Columns.Count - 1
DataGrid1(i).Col = j
xlSheet(i).Cells(o + 2, j + 1) = DataGrid1(i).Text
Next
If o < DataGrid1(i).ApproxCount - 1 Then
DataGrid1(i).Row = DataGrid1(i).Row + 1
End If
Next
Me.MousePointer = 0
Set xlSheet(i) = Nothing
Next i
Set xlApp = Nothing
Set xlBook = Nothing
End Sub
以上代码哪里错了吗?怎么只能输出一次?
进程为何关不掉?请高手解答或修改下代码,谢谢了. \\
\
问题补充:我这里说的只能输出一次,是指每次打开应用程序只能成功输出一份表,然后必须将表格进程关掉,再打开应用程序才能再次输出