Private Sub Database_excel() '******导出到excel区
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Columns.AutoFit
Me.MousePointer = 11
For k = 0 To DataGrid1.Columns.Count - 1
xlSheet.Cells(1, k + 1) = DataGrid1.Columns(k).Caption
Next
DataGrid1.Scroll 0, -DataGrid1.FirstRow
DataGrid1.Row = 0
For i = 0 To DataGrid1.ApproxCount - 1 For j = 0 To DataGrid1.Columns.Count - 1
DataGrid1.Col = j
xlSheet.Cells(i + 2, j + 1) = DataGrid1.Text
Next
If i < DataGrid1.ApproxCount - 1 Then
DataGrid1.Row = DataGrid1.Row + 1
End If
Next '
Me.MousePointer = 0
MsgBox "导出成功!"
xlApp.Visible = True
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub
这是导出到excel的代码,导出没有问题,但是当导出的数据像:901240000097232038411060123这样长的时候,导到额excel的就变成:9.0124E+26 这样了。代码需要怎么改???谢谢了。
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Columns.AutoFit
Me.MousePointer = 11
For k = 0 To DataGrid1.Columns.Count - 1
xlSheet.Cells(1, k + 1) = DataGrid1.Columns(k).Caption
Next
DataGrid1.Scroll 0, -DataGrid1.FirstRow
DataGrid1.Row = 0
For i = 0 To DataGrid1.ApproxCount - 1 For j = 0 To DataGrid1.Columns.Count - 1
DataGrid1.Col = j
xlSheet.Cells(i + 2, j + 1) = DataGrid1.Text
Next
If i < DataGrid1.ApproxCount - 1 Then
DataGrid1.Row = DataGrid1.Row + 1
End If
Next '
Me.MousePointer = 0
MsgBox "导出成功!"
xlApp.Visible = True
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub
这是导出到excel的代码,导出没有问题,但是当导出的数据像:901240000097232038411060123这样长的时候,导到额excel的就变成:9.0124E+26 这样了。代码需要怎么改???谢谢了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货