Dim i As Integer
Dim j As Integer
Dim myFile As New System.IO.StreamWriter("c:\Test.txt")
Dim strTemp As String = ""
For j = 0 To frmQuery.DataGridView1.RowCount - 1
strTemp = ""
For i = 0 To frmQuery.DataGridView1.Columns.Count - 1
strTemp &= "'" & frmQuery.DataGridView1(i, j).Value & "'" & ","
Next
myFile.WriteLine(strTemp)
Next
myFile.Close()
格式为表格每行保存为文本文件的一行,字段之间以逗号分隔。