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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading a word file and outputing the result

Status
Not open for further replies.

sltassassin01

Programmer
Jan 8, 2003
3
US
I'm writing a program in visual c++ 6.0. I have a microsoft word file that contains data. I need my program to open the word file, read from the file and output certain parts of the file into a database. I tried opening the file like i do with text files but it doesn't seem to work unless the file was created by c++ itself. It produces nonsense as an output. Could someone please help me out here.
 
Word files are formatted, you need to convert it to text format first. This can be done either by automating word or by some word interpreter. I think it's rather simple in VB. Or you can save the word file as text directly.
 
I tried saving it as a text file but most of the contents of the file was lost and stuff such as returns and tables were messed up. Is there a way to convert word to a text file without destroying the data
 
I don't know much about word conversion but did you try to do this in binary mode?
fstream outfile("output.txt" ios::eek:ut|ios::binary);
you will need to use outfile.read() and outfile.write() rather than outfile << data; I don't think this will do exactly what you were looking for but if you figure out how the conversion works it may be useful. Marshall Leitem
 
I don't know much about word conversion but did you try to do this in binary mode?
fstream outfile(&quot;output.txt&quot; ios::eek:ut|ios::binary);
you will need to use outfile.read() and outfile.write() rather than outfile << data; I don't think this will do exactly what you were looking for but if you figure out how the conversion works it may be useful.
Marshall Leitem
 
I forgot to include this in my last post, the reason you are getting a bunch of junk is because you are probably reading a binary file into some sort of character or string. that is why binary must be used to preserve the original file contents. anything that isn't in plain text such as a notepad file must be done in binary mode, such as a .exe file it must be done in binary mode as i stated in my last post. hope this helps Marshall Leitem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top