Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert MS word file to text file

Posted on 2011-09-08
6
Medium Priority
?
354 Views
Last Modified: 2012-06-21
Hi,

I have to convert a MS-word (*.doc/*.docx) file to a text file (*.txt) using a VC++ and MFC.

The problem faced while conversion is that When I try to convert word file to text file the text file is not in the readable form. It shows the text in the form like "´•IOÃ0…ïHü‡ÈW”¸p@5åÀr„JqvIj/ò¸Û¿gÜ%j«¶)P.‘ç½÷yœ™tfºN&àQY“³ë¬Ã0ÒÊT9û¼¤w,Á L!jk  ".

Reverse conversion, I mean from text to *.doc is working fine.

I checked the font properties are also same. Even I pasted the converted garbage text to word file, but it produced the same garbage one.

Welcome if any further information required.

Thanks
0
Comment
Question by:harshvir_drish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36501022
How do you perform the conversion?
0
 

Author Comment

by:harshvir_drish
ID: 36501518
I am doing this task using VC+ program.

Pl. find the code snippet , developed by me for this purpose.

         
CFile File1;
	char Buff[15024];
	File1.Open(m_SourceFile,CFile::modeRead);
	UINT Bytes = File1.Read(Buff,15024);
	CFile File2;
	File2.Open(L"c:\\MyFile.txt",CFile::modeCreate|CFile::modeWrite);
	File2.Write(Buff,Bytes);

Open in new window


Waiting for your appreciable response.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36501565
Thought so.  A word document is not text, it has other information in it.  What you are doing is effectively renaming xx.doc to xx.txt.  Hence you see garbage.
0
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 

Author Comment

by:harshvir_drish
ID: 36501656
Yes I tested the same by opening the same word file with notepad and the output is same as generated by my code.

So, Can you guide further?

Thanks for your quick and appreciable response.
0
 
LVL 4

Expert Comment

by:pgorod
ID: 36514087
1. I would do it from within Word, with a Macro, a simple "Save as..." text.

From MFC, there are ways to handle Word from there (COM automation object):
http://support.microsoft.com/kb/196776

But the basic idea is that Microsoft Word knows about it's format, you should use their code to convert.

2. A totally different approach, only for docx format (does not work for .doc!) is that you can unzip a docx and you will see text files with the document content; these are in XML and the format is documented by Microsoft.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 36515440
>>So, Can you guide further?

Two possiblities spring to mind.
Already mentioned is controlling word via automation.
The other is to send a message to word to copy the open document to the clipboard, then your app reads the clipboard and saves to .txt file.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question