473,473 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

convert text file to excel ?

How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 TestAddress1 111-2222

lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long

I want to put the Data in Excel as follows:
A B C D
1 11002 Test1 TestAddress1 111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? thanks
Nov 17 '08 #1
15 17347
If you don't need to specify formatting for the Excel items, you could save
the file in CSV format. That will import into Excel as a simple list of
fields. The name and address items will need to be wrapped in quotes, as
they could include commas. Or, use TAB instead of comma and accept the
Excel default during import..
http://www.cknow.com/ckinfo/c/CSV-Co...atedValue.html

<pa*****@gmail.comwrote in message
news:f5**********************************@a26g2000 prf.googlegroups.com...
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 TestAddress1 111-2222

lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long

I want to put the Data in Excel as follows:
A B C D
1 11002 Test1 TestAddress1 111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? thanks
Nov 17 '08 #2
Its not TAB delimited though. Its 10 characters, a space, 10more, etc.

I cant put quotes around a field because this is the way I get a file,
no quotes. And there will never be a coma in that field the way this
file comes out.

On Nov 17, 6:06*pm, "James Hahn" <jh...@yahoo.comwrote:
If you don't need to specify formatting for the Excel items, you could save
the file in CSV format. *That will import into Excel as a simple list of
fields. *The name and address items will need to be wrapped in quotes, as
they could include commas. *Or, use TAB instead of comma and accept the
Excel default during import..http://www.cknow.com/ckinfo/c/CSV-Co...atedValue.html

<pake...@gmail.comwrote in message

news:f5**********************************@a26g2000 prf.googlegroups.com...
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER * * *NAME * * * * * * ADDRESS * * * * * * * *PHONE
11002 * * * * * Test1 * * * * * * * TestAddress1 * * * * * 111-2222
lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long
I want to put the Data in Excel as follows:
* * * * *A * * * * * * B * * * * * *C* * * * * * * * D
1 * * 11002 * * * Test1 * * *TestAddress1 *111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? *thanks
Nov 17 '08 #3
I think that James Hahn was suggesting, and if he wasn't I am, that you
could write a simple text manipulation program which places a comma or tab
character between the values. Such a file can be read by Excel.
<pa*****@gmail.comwrote in message
news:f4**********************************@1g2000pr d.googlegroups.com...
Its not TAB delimited though. Its 10 characters, a space, 10more, etc.

I cant put quotes around a field because this is the way I get a file,
no quotes. And there will never be a coma in that field the way this
file comes out.

On Nov 17, 6:06 pm, "James Hahn" <jh...@yahoo.comwrote:
If you don't need to specify formatting for the Excel items, you could
save
the file in CSV format. That will import into Excel as a simple list of
fields. The name and address items will need to be wrapped in quotes, as
they could include commas. Or, use TAB instead of comma and accept the
Excel default during
import..http://www.cknow.com/ckinfo/c/CSV-Co...atedValue.html

<pake...@gmail.comwrote in message

news:f5**********************************@a26g2000 prf.googlegroups.com...
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 TestAddress1 111-2222
lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long
I want to put the Data in Excel as follows:
A B C D
1 11002 Test1 TestAddress1 111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? thanks

Nov 18 '08 #4
Sorry, my previous reply, below, was sent before I had finished it. The
complete reply which I had intended was ...

I think that James Hahn was suggesting, and if he wasn't I am, that you
could simply write a simple text manipulation program which places a comma
or tab character between the values. Such a file can be read by Excel. You
CAN interface with Excel to create an Excel spreadsheet and it's a lot of
fun. But given your requirements, as you've explained them, you could just
write a text file and save considerable effort. (Although you will have
less fun!)

Bob

"eBob.com" <fa******@totallybogus.comwrote in message
news:eG**************@TK2MSFTNGP03.phx.gbl...
>I think that James Hahn was suggesting, and if he wasn't I am, that you
could write a simple text manipulation program which places a comma or tab
character between the values. Such a file can be read by Excel.
<pa*****@gmail.comwrote in message
news:f4**********************************@1g2000pr d.googlegroups.com...
Its not TAB delimited though. Its 10 characters, a space, 10more, etc.

I cant put quotes around a field because this is the way I get a file,
no quotes. And there will never be a coma in that field the way this
file comes out.

On Nov 17, 6:06 pm, "James Hahn" <jh...@yahoo.comwrote:
>If you don't need to specify formatting for the Excel items, you could
save
the file in CSV format. That will import into Excel as a simple list of
fields. The name and address items will need to be wrapped in quotes, as
they could include commas. Or, use TAB instead of comma and accept the
Excel default during
import..http://www.cknow.com/ckinfo/c/CSV-Co...atedValue.html

<pake...@gmail.comwrote in message

news:f5**********************************@a26g200 0prf.googlegroups.com...
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 TestAddress1 111-2222
lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long
I want to put the Data in Excel as follows:
A B C D
1 11002 Test1 TestAddress1 111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? thanks


Nov 18 '08 #5
What I was suggesting was that you process the file by reading your input
text file, separating out the fields according to your fixed-width field
structure and write out a new file that is CSV format (with text fields
quoted for preference) or as a tab-delimited file (quoting not required.

This is not an XLS file, but it can be opened in Excel. The drawback is that
you cannot specify formatting for the columns, but you haven't indicated
whether that's an issue.

The advantage of tab delimited is that the file will import into Excel using
default values for the process. Since your existing file will also import
into Excel, but requires user intervention or a macro) to specify the column
widths, I assume that unattended import is important for your project.

Creating an XLS file is a much larger task that you probably wouldn't tackle
without assistance, but it does give you control over the resulting
worksheet. Here's some examples:
http://www.bytescout.com/bytescoutxls.html
http://www.codeplex.com/ExportToExcel

An alternative is to process the source file into a database that Excel can
understand. Look in this NG from a few days ago for "Exporting to Excel".

<pa*****@gmail.comwrote in message
news:f4**********************************@1g2000pr d.googlegroups.com...
Its not TAB delimited though. Its 10 characters, a space, 10more, etc.

I cant put quotes around a field because this is the way I get a file,
no quotes. And there will never be a coma in that field the way this
file comes out.
Nov 18 '08 #6
On Nov 17, 8:08*pm, "eBob.com" <faken...@totallybogus.comwrote:
Sorry, my previous reply, below, was sent before I had finished it. *The
complete reply which I had intended was ...

I think that James Hahn was suggesting, and if he wasn't I am, that you
could simply write a simple text manipulation program which places a comma
or tab character between the values. *Such a file can be read by Excel.*You
CAN interface with Excel to create an Excel spreadsheet and it's a lot of
fun. *But given your requirements, as you've explained them, you could just
write a text file and save considerable effort. *(Although you will have
less fun!)

Bob

"eBob.com" <faken...@totallybogus.comwrote in message

news:eG**************@TK2MSFTNGP03.phx.gbl...
I think that James Hahn was suggesting, and if he wasn't I am, that you
could write a simple text manipulation program which places a comma or tab
character between the values. *Such a file can be read by Excel.
<pake...@gmail.comwrote in message
news:f4**********************************@1g2000pr d.googlegroups.com...
Its not TAB delimited though. Its 10 characters, a space, 10more, etc.
I cant put quotes around a field because this is the way I get a file,
no quotes. And there will never be a coma in that field the way this
file comes out.
On Nov 17, 6:06 pm, "James Hahn" <jh...@yahoo.comwrote:
If you don't need to specify formatting for the Excel items, you could
save
the file in CSV format. That will import into Excel as a simple list of
fields. The name and address items will need to be wrapped in quotes, as
they could include commas. Or, use TAB instead of comma and accept the
Excel default during
import..http://www.cknow.com/ckinfo/c/CSV-Co...atedValue.html
<pake...@gmail.comwrote in message
>news:f5**********************************@a26g200 0prf.googlegroups.com....
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 TestAddress1 111-2222
lets say the number field is 10 characters long, there is a space and
Name field is 15 characters long, there is a space, address can be 25
characters long, there is a space and phone is 10 characters long
Well my initial reaction to this was just that. Write a little program
that opens a file, Removes the first two lines, because I really don't
need the headings, moves over 10 spaces and inserts a tab, moves over
15 and inserts a tab and then saves the file as .xls

My problem is I only have figured out how to read in a file so far :(
>
I want to put the Data in Excel as follows:
A B C D
1 11002 Test1 TestAddress1 111-2222
So I need to read a text file, put the contents into an excel file and
save it as .xls
And can this be done as a service?...or does it have to be an .exe in
vb 2008? thanks
Nov 18 '08 #7
What part of the process are you having a problem with? Parsing the input,
creating the output, creating the output file, writing to the output file,
etc?

<pa*****@gmail.comwrote in message
news:36**********************************@w24g2000 prd.googlegroups.com...
On Nov 17, 8:08 pm, "eBob.com" <faken...@totallybogus.comwrote:
snip <
Well my initial reaction to this was just that. Write a little program
that opens a file, Removes the first two lines, because I really don't
need the headings, moves over 10 spaces and inserts a tab, moves over
15 and inserts a tab and then saves the file as .xls

My problem is I only have figured out how to read in a file so far :(

Nov 18 '08 #8
<pa*****@gmail.comschrieb
My problem is I only have figured out how to read in a file so far :(
Help helps:
http://msdn.microsoft.com/en-us/library/k3352a4t.aspx
http://msdn.microsoft.com/en-us/library/ws92aysc.aspx

Armin
Nov 18 '08 #9
I can read in a file.
How would I read over 10 lines, insert a TAB, read over 15 more,
Insert a TAB?

And how can this than automatically be saved out as excel?

On Nov 18, 3:06*am, "Armin Zingler" <az.nos...@freenet.dewrote:
<pake...@gmail.comschrieb
My problem is I only have figured out how to read in a file so far :(

Help helps:http://msdn.microsoft.com/en-us/libr.../ws92aysc.aspx

Armin
Nov 18 '08 #10
Here is what I am doing to read in the file....And I put the contents
in a textbox just to know that it is being read.

Dim myclient As New System.Net.WebClient
txtbox1.Text = myclient.DownloadString("C:\Documents and
Settings\user\Desktop\mytestfile.txt")

On Nov 18, 9:04*am, pake...@gmail.com wrote:
I can read in a file.
How would I read over 10 lines, insert a TAB, read over 15 more,
Insert a TAB?

And how can this than automatically be saved out as excel?

On Nov 18, 3:06*am, "Armin Zingler" <az.nos...@freenet.dewrote:
<pake...@gmail.comschrieb
My problem is I only have figured out how to read in a file so far :(
Help helps:http://msdn.microsoft.com/en-us/libr...tp://msdn.micr...
Armin
Nov 18 '08 #11
<pa*****@gmail.comschrieb
>>My problem is I only have figured out how to read in a file so far :(
I can read in a file.
Sorry, my mistake! I read "I haven't figured out..."
Armin

Nov 18 '08 #12
Start with reading in the file. Once you have your data in some kind
of easily manipulated format (i.e. User created objects, string
arrays, etc.) you can loop over the collection and put them into the
Excel spreadsheet.

As I commented on another thread there is a way to use ODBC to query
an existing spreadsheet and so also possible to use an Insert/Update/
Delete statement. At that point just treat the spreadsheet as a
database. Same drawback is that you can't format the columns
automatically.

Another option is to grab the Excel object model and attempt to use
that. Of all the Office interops its probably the best since Excel at
least somewhat behaves like a database table. With this you can do
formatting on cells/rows/columns, but the documentation is somewhat
spotty when you get into that.
Nov 18 '08 #13
NOT tested or checked.

Dim sw as New StreamWriter ("C:\Documents and
Settings\user\Desktop\myEXCELfile.txt")
Dim a() as string
a = Split(txtbox1.text, vbCRLF)

dim e(10) as string
for each s as string in a
e(0) = s.Substring(0,10)
e(1) = s.Substring(10,15)
< etc >

dim b as String = Join(e, Ctype(Chr(8),String))
sw.WriteLine(b)
Next
sw.Close()

<pa*****@gmail.comwrote in message
news:80**********************************@35g2000p ry.googlegroups.com...
I can read in a file.
How would I read over 10 lines, insert a TAB, read over 15 more,
Insert a TAB?

And how can this than automatically be saved out as excel?

On Nov 18, 3:06 am, "Armin Zingler" <az.nos...@freenet.dewrote:
<pake...@gmail.comschrieb
My problem is I only have figured out how to read in a file so far :(

Help
helps:http://msdn.microsoft.com/en-us/libr.../ws92aysc.aspx

Armin
Nov 18 '08 #14
I'm totally lost....Can anyone show me how to do this?
Basically read in a file
Loop through it and at 10 spaces insert a TAB or coma
at 15 spaces insert another TAB or coma

Save the file out as an excel .xls or csv whichever will put these
records into A1, B1, C1, A2, B2, C2 etc ?

And if anyone is willing to do this could you document where the TABS
or comas are being put in and where the file is beting re-written out?

thanks, in the mean time i'll keep playing with this.
On Nov 18, 11:08*am, "cfps.Christian" <ge0193...@otc.eduwrote:
Start with reading in the file. *Once you have your data in some kind
of easily manipulated format (i.e. User created objects, string
arrays, etc.) you can loop over the collection and put them into the
Excel spreadsheet.

As I commented on another thread there is a way to use ODBC to query
an existing spreadsheet and so also possible to use an Insert/Update/
Delete statement. *At that point just treat the spreadsheet as a
database. *Same drawback is that you can't format the columns
automatically.

Another option is to grab the Excel object model and attempt to use
that. *Of all the Office interops its probably the best since Excel at
least somewhat behaves like a database table. *With this you can do
formatting on cells/rows/columns, but the documentation is somewhat
spotty when you get into that.
Nov 18 '08 #15
<pa*****@gmail.comschrieb
I'm totally lost....Can anyone show me how to do this?
Basically read in a file
Loop through it and at 10 spaces insert a TAB or coma
at 15 spaces insert another TAB or coma

Save the file out as an excel .xls or csv whichever will put these
records into A1, B1, C1, A2, B2, C2 etc ?

And if anyone is willing to do this could you document where the
TABS or comas are being put in and where the file is beting
re-written out?

thanks, in the mean time i'll keep playing with this.
Maybe the probelm is we don't know what exactly is the problem you are
having.

First, use System.IO.File.ReadAllLines to read all lines into an Array of
Strings.

I think how to write a loop is known. With every line, you can do what you
described above. Use the String's SubString method to get a part of a
String. Use the & operator to concatenate two strings. You can store the
result back in the array. After the loop is done, write the file back (I
suggest to a new file). This can be done with the
System.IO.File.WriteAllLines method.
Armin

Nov 19 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kittu_phani | last post by:
Hi I want to transfer the data in text files into Ms Access using a C program. Please suggest me the code with supporting files. Thanks in advance Krishna -- Posted via http://dbforums.com
1
by: Mike | last post by:
I need to search a server to see if files exist on that server or not. If the file does not exsit I need to write the filename to a text file, excel file, etc. what file acutally I have a list...
1
by: davihigh | last post by:
Dear Friends: Wondering that is there neat way to do "subject line" in Python? I am talking about Python 2.4 with Win32 extension installed. The locale can be any of ANSI defined, for example,...
4
by: AHP | last post by:
Hi, I'm using Visual Studio 2005. I am developing a web application that uses the FileUpload control to upload text files to a directory on a webserver. This works fine. However, for me to be...
0
by: klaydze | last post by:
i have created program that convert txt file to .tiff file. but i cant work out in jpg. anyone can give me a line of code that can i use?thx in advance
5
by: gaya3 | last post by:
Hi all, How to convert text file to excel file in java?? pl any one help me out... is ter any api..??
0
by: binh2807 | last post by:
Hi! Psl help me I have a morse application. I want to convert morse text file into wav file or mp3 file for me play it by windows media player. How can i do it. Thanks.
1
by: agarwalsunitadhn | last post by:
Hi I am developing an application in which i need to convert a text file into a resource file and then serach different resources from the resource file. I want to know how to create the resource...
0
by: ravitunk | last post by:
hello....Can anyone tell me how to convert a text file to PDF using VB6...Plz reply soon..I will be thankful...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.