vb6.0 Datagrid显示数据导出
时间: 2024-01-08 21:04:41 浏览: 244
以下是使用VB6.0将Datagrid中的数据导出的示例代码:
Private Sub cmdExport_Click()
Dim fso As FileSystemObject
Dim ts As TextStream
Dim sLine As String
Dim iLoop As Integer
Dim iCol As Integer
Set fso = New FileSystemObject
Set ts = fso.CreateTextFile("C:\DataGridExport.txt", True)
'导出Datagrid的列标题
For iCol = 0 To DataGrid1.Columns.Count - 1
sLine = sLine & DataGrid1.Columns(iCol).Caption & vbTab
Next
ts.WriteLine sLine
'导出Datagrid的数据
With DataGrid1
For iLoop = 0 To .RowCount - 1
sLine = ""
For iCol = 0 To .Columns.Count - 1
sLine = sLine & .Columns(iCol).CellText(iLoop) & vbTab
Next
ts.WriteLine sLine
Next
End With
ts.Close
Set ts = Nothing
Set fso = Nothing
MsgBox "数据已成功导出到C:\DataGridExport.txt文件中。"
End Sub
此代码将Datagrid中的数据导出到文本文件中,可以自行修改文件路径和文件名。
阅读全文