可以把excel的东西先导入到datatable中,然后再导成txt格式
下面是导入到datatable的例子
Dim openbox As New OpenFileDialog
openbox.ShowDialog()
Dim filename As String = openbox.FileName
Dim myConn As New System.Data.OleDb.OleDbConnection
Dim strComMain As String = " SELECT * FROM [12$]"
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 4.0;HDR=no"""
myConn.Open()
Catch ex As Exception
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 1.0;HDR=no"""
myConn.Open()
Catch ex1 As Exception
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 8.0;HDR=no"""
myConn.Open()
Catch ex2 As Exception
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 3.0;HDR=no"""
myConn.Open()
Catch ex3 As Exception
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 2.1;HDR=no"""
myConn.Open()
Catch ex4 As Exception
Try
myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & filename & ";Extended Properties=""Excel 5.0;HDR=no"""
myConn.Open()
Catch ex5 As Exception
MsgBox(ex5.Message)
End Try
End Try
End Try
End Try
End Try
End Try
Dim myCommandMain As New System.Data.OleDb.OleDbDataAdapter(strComMain, myConn)
Dim myData = New DataTable
Try
myCommandMain.Fill(myData)
Catch ex As Exception
MsgBox(ex.Message)
Finally
myConn.Close()
End Try