VB Dategrid数据导入Excel中的问题
PrivateSubCommand2_Click()DimexAsObjectDimiAsIntegerDimjAsIntegerDimXlAppAsExcel.Appl...
Private Sub Command2_Click()
Dim ex As Object
Dim i As Integer
Dim j As Integer
Dim XlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
For i = 0 To DataGrid1.Columns.Count
For j = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Col = i
On Error Resume Next
DataGrid1.Row = j
xlSheet.Cells(j + 2, i + 1) = DataGrid1.Columns.Item(i).Text
Next j
Next i
End Sub
请问一下,这段程序可以导出来,但是DateGrid显示了很多记录,屏幕中显示出来的可以导出来,但是有些记录屏幕没显示出来(可以通过下来条显示出来),屏幕显示出来的记录导出来是正确的,屏幕没显示出来的记录就是错误的,下面导出的记录都是屏幕显示出来的最后一条,也不知道是什么问题,麻烦各位大神帮忙把这个程序修改一下,谢谢~ 展开
Dim ex As Object
Dim i As Integer
Dim j As Integer
Dim XlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
For i = 0 To DataGrid1.Columns.Count
For j = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Col = i
On Error Resume Next
DataGrid1.Row = j
xlSheet.Cells(j + 2, i + 1) = DataGrid1.Columns.Item(i).Text
Next j
Next i
End Sub
请问一下,这段程序可以导出来,但是DateGrid显示了很多记录,屏幕中显示出来的可以导出来,但是有些记录屏幕没显示出来(可以通过下来条显示出来),屏幕显示出来的记录导出来是正确的,屏幕没显示出来的记录就是错误的,下面导出的记录都是屏幕显示出来的最后一条,也不知道是什么问题,麻烦各位大神帮忙把这个程序修改一下,谢谢~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询