Text File to Excel Split delimiters

  • Thread starter Thread starter stizalke
  • Start date Start date
S

stizalke

Guest
Hi. Its me again, with the excel problem.

I am looking for method to convert from text file to excel file (.xlsx). but in the same time it also can split the delimiters ("|").

I try and error this code,

Public Sub separatetxt()

Dim fileToRead As String = "\3\pendingpgi_.txt"
Dim fileStream As StreamReader = File.OpenText(fileToRead)
Dim readContents As String = fileStream.ReadToEnd()
Dim repContents As String = Replace(readContents, "|", vbTab)
fileStream.Close()
Dim filename As String = "\3\pendingpgi.xls"
Dim convert As Boolean = SaveTextToFile(repContents, filename)


End Sub

Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean

Dim bAns As Boolean = False
Dim objReader As StreamWriter
Try
objReader = New StreamWriter(FullPath)
objReader.Write(strData)
objReader.Close()
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
Return bAns

End Function


using this method, I try to get the xlsx format, but cannot open the file because of the different format.

and it can work with xls format.


Please help me anyone, to get the excel file from text file. I am so stuck with this program for a very long time huhuuh T_T

Continue reading...
 
Back
Top