How to convert a .txt file extension to a .xls file extension?

S

Steve

Using VB.NET, How do I convert a .txt file extension to a .xls file
extension? The text file is already created and saved in a folder on the
server.
Thanks
Steven
 
L

Laurent Bugnion

Hi,

Augustin said:
Steve,

System.IO.File.Move("c:\test.txt", "c:\test.xls")

If the text file is really just a text file, changing its extension will
not convert it to an excel file magically...

If you have a text file, you'll need to parse it and insert the data in
the Excel file. Fortunately, you can use ADO.NET to connect to Excel
files like to a DB (though with some restrictions), so it's not that
complicated to interact with Excel files even in environments where
Excel itself is not available or cannot be automated.

HTH,
Laurent
 
S

Steve

Thanks guys, I haven't tried System.IO.File.Move("c:\test.txt",
"c:\test.xls") yet, but I have found that the following code will magically
produce an Excel file with cells A1:A5 populated: This is not documented
anywhere, I just tried it to see what would happen!


Dim pathAndFileName As String = Server.MapPath("Data/Test.xls")

Dim sr As StreamWriter = File.CreateText(pathAndFileName)

Dim xData, str_1,str_2,str_3,str_4,str_5 As String

str_1="This"

str_2="is"

str_3="a"

str_4="Test"

xData = "str_1 & vbTab & str_2 & vbTab & str_3 & vbTab & str_4

sr.WriteLine(xData)

sr.Close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top