locked
Convert ms-word file to text file

    Question

  • 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
    Thursday, September 08, 2011 6:36 AM

All replies

  • >I want to convert a ms-word file to a text file using vc++(MFC). How can i do this?

    If your users will have MS Word installed, you could control Word
    through automation to invoke its Save As facility. If they don't, then
    the solution may depend on which version of Word documents you need to
    handle.

    Dave

    Thursday, September 08, 2011 8:10 AM
  • Not at all David.

    We have to handle this situation programmatic way only.

    Presently my system has been installed with MS Office 2010. But during program I have to handle all teh MS office versions. 

    Code snippet used by me is :-

    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);
    


    Where we have to specify or handle the version of word. If possible how to handle this one. 

    Is it using *.doc or *.docx ? 

     

     


    Prabhjot Singh
    Thursday, September 08, 2011 9:41 AM
  • >Presently my system has been installed with MS Office 2010. But during program I have to handle all teh MS office versions. 

    What version of Word (if any) will your target users have installed?

    Assuming the users of your application will have Word installed, you
    normally have to target the lowest version your users will have. For
    starters, have a look here: http://support.microsoft.com/kb/196776

    Dave

    Thursday, September 08, 2011 11:48 AM