Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using word or excel to extract/parse data from text-only file?

Status
Not open for further replies.

jhherring

Programmer
Jun 18, 2002
33
US

I'm fairly conversant with Word and Excel, so I feel fairly sure this CAN be done, but I'm having trouble figuring out exactly how. If the answer involves using Access or MS Query, that's OK too, but step-by-step instructions would be appreciated in that case.

I have a number of text-only files, sent to an e-mail address by a form on a web site. They all look like this:

LastName: Smith
FirstName: John
Address1: 123 Main Street
Address2:
City: Anytown
State: NY
Zip: 12345
e-mail: name@domain.com

And many other fields. Please note that blanks do occur, and would have to be taken into account in any solution.

I need to take the values entered by the user in the web form, and get them to appear within mail merge fields in Word. I have the form all set up in Word, and the client loves the way it looks. The only thing we need now is to extract the values, ignoring the field labels generated by the CGI script, and dump them into the proper fields in the Word file.

I have the freedom to rename the fields in the CGI script to anything I want. I can even make all the fields exactly the same length (field0001, field0002, etc.) if that would help. I need the parsing routine to ignore everything on each line up to and including the colon and the space following it, and then get everything after that up to the EOL. Then repeat that for every form field.

I can easily search and replace in the Word file to make all the colon-spaces into tabs, convert the resulting tab-delimited text into a table, and then eliminate the first column completely, but then I'm just left with a column of values, and I'm not sure what to do next to make that column into a data source for Word to pull from.

I feel like I'm close to the solution, just a couple of pieces of the puzzle missing. Any help you can provide will be gratefully accepted.


Thanks!


 
I might suggest that you download the data Template Wizard for Excel 2002/2003. With that you can use the Web forms to populate a database and then Word can read the database and complete the mail merge. This is a wizard where you name the fields and the wizard reads the names and populates a data sheet...it works really slick (at least the old vs 2000 does!

I haven't used this new template, but I have used it in prior versions when the wizard wasn't an add-in.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top