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

Discussion in 'ASP .Net' started by Steve, Aug 24, 2006.

  1. Steve

    Steve Guest

    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
    Steve, Aug 24, 2006
    #1
    1. Advertising

  2. 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
    >
    >
    >
    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmE=?=, Aug 25, 2006
    #2
    1. Advertising

  3. 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
    Laurent Bugnion, Aug 25, 2006
    #3
  4. Steve

    Steve Guest

    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" <> wrote in message
    news:...
    > 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
    Steve, Aug 25, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A B
    Replies:
    1
    Views:
    2,885
    Peter O'Reilly
    May 13, 2004
  2. Enrique

    xls to txt

    Enrique, Oct 16, 2003, in forum: Python
    Replies:
    2
    Views:
    500
    Jon =?iso-8859-1?q?K=E5re?= Hellan
    Oct 17, 2003
  3. Sameen
    Replies:
    2
    Views:
    425
    Victor Bazarov
    Aug 29, 2005
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,486
    Roedy Green
    Sep 15, 2011
  5. Sara
    Replies:
    5
    Views:
    122
Loading...

Share This Page