用vb让txt文件转换excel文件的教程
学习啦在线学习网用vb让txt文件转换excel文件的教程
在Excel的录入过程中经常需要用到TXT转Excel,其中可以用VB把TXT文件换成Excel,具体要怎么做呢?下面是学习啦小编带来的关于用vb让txt文件转换excel文件的教程,希望阅读过后对你有所启发!
用vb让txt文件转换excel文件的教程:
学习啦在线学习网 vb让TXT转换excel步骤:下面是导入到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
看了用vb让txt文件转换excel文件的教程还看了: