PC Review


Reply
Thread Tools Rate Thread

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

 
 
Steve
Guest
Posts: n/a
 
      24th Aug 2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QXVndXN0aW4gUHJhc2FubmE=?=
Guest
Posts: n/a
 
      25th Aug 2006
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
>
>
>

 
Reply With Quote
 
Laurent Bugnion
Guest
Posts: n/a
 
      25th Aug 2006
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
 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      25th Aug 2006
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" <galasoft-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change file extension to a different extension? =?Utf-8?B?QnJpYW4gV2lsbGlhbXM=?= Windows XP General 3 7th Oct 2005 05:16 PM
xls file extension to wks "Works" extension RussM Microsoft Excel Misc 1 11th Jul 2004 02:49 AM
How to convert Content-Type to file extension Anony Microsoft Dot NET 2 20th May 2004 09:16 PM
Shell Extension -adding file name/command extension LuckyStrike Microsoft Outlook Discussion 23 13th Sep 2003 02:27 AM
Convert music file extension steve Windows XP Hardware 0 28th Aug 2003 06:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.