學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 工具軟件 > 辦公軟件學(xué)習(xí) > Excel教程 > Excel基礎(chǔ) > 用vb讓txt文件轉(zhuǎn)換excel文件的教程

用vb讓txt文件轉(zhuǎn)換excel文件的教程

時(shí)間: 業(yè)華773 分享

用vb讓txt文件轉(zhuǎn)換excel文件的教程

  在Excel的錄入過(guò)程中經(jīng)常需要用到TXT轉(zhuǎn)Excel,其中可以用VB把TXT文件換成Excel,具體要怎么做呢?下面是學(xué)習(xí)啦小編帶來(lái)的關(guān)于用vb讓txt文件轉(zhuǎn)換excel文件的教程,希望閱讀過(guò)后對(duì)你有所啟發(fā)!

  用vb讓txt文件轉(zhuǎn)換excel文件的教程:

  vb讓TXT轉(zhuǎn)換excel步驟:下面是導(dǎo)入到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文件轉(zhuǎn)換excel文件的教程還看了:

1.如何將Excel轉(zhuǎn)換成txt,txt轉(zhuǎn)為Excel

2.如何將txt轉(zhuǎn)換excel的方法

3.如何將txt導(dǎo)入excel的教程

4.excel2010導(dǎo)入txt的教程

5.Word2010如何轉(zhuǎn)換DOC與TXT格式

6.怎么將txt中的數(shù)據(jù)導(dǎo)入到excel2007

7.Excel2010工作表中如何導(dǎo)入txt文件?

696567