469,643 Members | 1,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

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

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
Aug 24 '06 #1
3 3484
Steve,

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

Regards,
Augustin
http://augustinprasanna.blogspot.com

"Steve" wrote:
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
Aug 25 '06 #2
Hi,

Augustin Prasanna wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 25 '06 #3
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()
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:O7**************@TK2MSFTNGP04.phx.gbl...
Hi,

Augustin Prasanna wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Aug 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tim | last post: by
13 posts views Thread by kbperry | last post: by
4 posts views Thread by csgraham74 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.