Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to convert .txt(ASCII) to MS Word file

How to convert .txt(ASCII) to MS Word file

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
16 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CPalliniC CPallini

    Smart hint, but technically there is no conversion until you'll open it with Word and then save it in Word own (.doc) format. :-D

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    [my articles]

    R Offline
    R Offline
    Rajesh R Subramanian
    wrote on last edited by
    #4

    It may not work the other way round though :laugh:

    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

    R 1 Reply Last reply
    0
    • R Rajesh R Subramanian

      It may not work the other way round though :laugh:

      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

      R Offline
      R Offline
      rajeevktripathi
      wrote on last edited by
      #5

      Actually what I want is to convert any .txt file to .doc (MS Word) one. So please tell me any programming approach or related DLL or SDK that will perform the objective. PLease help me Thanks & Regards Edit/Delete Message

      R CPalliniC 2 Replies Last reply
      0
      • R rajeevktripathi

        Actually what I want is to convert any .txt file to .doc (MS Word) one. So please tell me any programming approach or related DLL or SDK that will perform the objective. PLease help me Thanks & Regards Edit/Delete Message

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #6

        It is just one line of code.

        CFile::Rename(_T("E:\\myfile.txt"), _T("E:\\myfile.doc"));

        Keep it in mind that you are just renaming a file and you actually haven't done the conversion. It is perfectly safe in this case since MS Word will handle it. It won't work the other way round.

        Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

        K 1 Reply Last reply
        0
        • R rajeevktripathi

          Actually what I want is to convert any .txt file to .doc (MS Word) one. So please tell me any programming approach or related DLL or SDK that will perform the objective. PLease help me Thanks & Regards Edit/Delete Message

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #7

          You have to pass through COM automation see this article http://www.codeguru.com/cpp/misc/misc/microsoftofficeoutlook/article.php/c14519/[^] looks promising. Good luck. BTW doing it with a script language (such as VBScript or JScript) is far easier.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          In testa che avete, signor di Ceprano?

          R 1 Reply Last reply
          0
          • CPalliniC CPallini

            You have to pass through COM automation see this article http://www.codeguru.com/cpp/misc/misc/microsoftofficeoutlook/article.php/c14519/[^] looks promising. Good luck. BTW doing it with a script language (such as VBScript or JScript) is far easier.

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            [my articles]

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #8

            CPallini wrote:

            VBScript or JScript

            X|

            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

            CPalliniC 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              CPallini wrote:

              VBScript or JScript

              X|

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #9

              Don't you like (those) scripting languages? :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              In testa che avete, signor di Ceprano?

              R 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                It is just one line of code.

                CFile::Rename(_T("E:\\myfile.txt"), _T("E:\\myfile.doc"));

                Keep it in mind that you are just renaming a file and you actually haven't done the conversion. It is perfectly safe in this case since MS Word will handle it. It won't work the other way round.

                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #10

                It is to hard for him to understand the elegance of your approach. :-O

                Greetings from Germany

                R 1 Reply Last reply
                0
                • R rajeevktripathi

                  Hi Al How can a text file be converted to MS Word format. Any idea regarding this is welcomed (Dll, SDK, or sample or precess to convert). Thanks in Advance. BYE

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #11

                  Can you use Word Automation like:

                  COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
                  vtDoc((short) 0);

                  if (app.CreateDispatch("Word.Application") == TRUE)
                  {
                  docs = app.GetDocuments();

                  CString strFileName = "myfile.txt";
                  
                  doc = docs.Open(COleVariant(strFileName), 
                                  vtOptional, vtOptional, vtOptional, 
                                  vtOptional, vtOptional, vtOptional, 
                                  vtOptional, vtOptional, vtOptional, 
                                  vtOptional, vtOptional);
                  
                  strFileName.Replace(".txt", ".doc");
                  
                  doc.SaveAs(COleVariant(strFileName), vtDoc, 
                             vtOptional, vtOptional, vtOptional,
                             vtOptional, vtOptional, vtOptional,  
                             vtOptional, vtOptional, vtOptional);
                  

                  }

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  1 Reply Last reply
                  0
                  • K KarstenK

                    It is to hard for him to understand the elegance of your approach. :-O

                    Greetings from Germany

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #12

                    KarstenK wrote:

                    It is to hard for him to understand the elegance of your approach.

                    Looks like that. But somebody has voted me a 1 also. I really don't understand what is wrong with my approach.

                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

                    1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      Don't you like (those) scripting languages? :-D

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      [my articles]

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #13

                      Yes, I don't like them. There's no fun in it.

                      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

                      CPalliniC 1 Reply Last reply
                      0
                      • R Rajesh R Subramanian

                        Yes, I don't like them. There's no fun in it.

                        Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. ...formerly known as brahmma Codeproject.com: Visual C++ MVP

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #14

                        Rajesh R Subramanian wrote:

                        Yes, I don't like them.

                        Well, that's a matter of personal taste, anyway they've many of defects but in fact I think there is a lot of fun dealing with (for instance, script components http://msdn2.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx[^] http://msdn2.microsoft.com/en-us/library/asxw6z3c%28VS.85%29.aspx[^] are, IMHO, amazing). :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        [my articles]

                        modified on Thursday, January 10, 2008 4:15:40 AM

                        In testa che avete, signor di Ceprano?

                        R 1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          Rajesh R Subramanian wrote:

                          Yes, I don't like them.

                          Well, that's a matter of personal taste, anyway they've many of defects but in fact I think there is a lot of fun dealing with (for instance, script components http://msdn2.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx[^] http://msdn2.microsoft.com/en-us/library/asxw6z3c%28VS.85%29.aspx[^] are, IMHO, amazing). :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          [my articles]

                          modified on Thursday, January 10, 2008 4:15:40 AM

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #15

                          I've been living with office automation via COM with a lot of help from MFC. If the OP had asked how to extract text content fro a .doc file, then I might have guided the OP to use COM. But then, somehow I don't like VBS and JS.

                          CPallini wrote:

                          script components http://msdn2.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx\[^\] are, IMHO, amazing).

                          That isn't any script component. You seem to have mistakenly pasted a different link. :)

                          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                          CPalliniC 1 Reply Last reply
                          0
                          • R Rajesh R Subramanian

                            I've been living with office automation via COM with a lot of help from MFC. If the OP had asked how to extract text content fro a .doc file, then I might have guided the OP to use COM. But then, somehow I don't like VBS and JS.

                            CPallini wrote:

                            script components http://msdn2.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx\[^\] are, IMHO, amazing).

                            That isn't any script component. You seem to have mistakenly pasted a different link. :)

                            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

                            CPalliniC Offline
                            CPalliniC Offline
                            CPallini
                            wrote on last edited by
                            #16

                            Rajesh R Subramanian wrote:

                            've been living with office automation via COM with a lot of help from MFC. If the OP had asked how to extract text content fro a .doc file, then I might have guided the OP to use COM.

                            David Crow has already done it.

                            Rajesh R Subramanian wrote:

                            But then, somehow I don't like VBS and JS.

                            Well, I underatand the feeling, for instance I dislike MFC in favour of the honest WIN32 API.

                            Rajesh R Subramanian wrote:

                            CPallini wrote: script components http://msdn2.microsoft.com/en-us/library/x5t0zfyf(VS.80).aspx\[^\] are, IMHO, amazing). That isn't any script component. You seem to have mistakenly pasted a different link.

                            You're right, my bad :-O. I fixed it (BTW I hope I didn't made a link swap... What help may have from Script Components the OP taht asked how to read a single line from a text filke? :-D ). Regards :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            [my articles]

                            In testa che avete, signor di Ceprano?

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups