No announcement yet.

replace tag in docx file using lua

  • Filter
  • Time
  • Show
Clear All
new posts

  • replace tag in docx file using lua

    Hi all.
    Does anyone know how we can change a word .docx programmability ??

  • #2
    Somethings like mail merging?


    • #3
      Lua can't interface with COM objects directly. So you'll need LuaCOM to interact with Word's Object model. It's very similar to using LuaCOM for interacting with Excel. Have a look at some work I did on this late last year, over here. There's a demo apz attached there. Although the example is specifically for Excel, Word will be very similar.

      There's also another thread specifically on Word & LuaCOM over here.

      Some advice from the wise - this topic is not for the faint of heart. It's quite challenging and I found the whole affair an exercise in sheer frustration. The biggest problem you'll encounter is that documentation available to help navigate this particular minefield is very sparse.

      Nb. And be prepared to deal with annoying COM errors frequently getting returned to AMS.


      • #4
        Microsoft Word *.docx are zipped XML and CSS files. You can decompress them, and edit the contents, if you are experienced in this, then compress the files back into a zip and rename back to the original extension.

        I have developed an application named "The Australian Résumé Writer" in the past. This product was designed for building résumés, and offered the creation of documents in OpenOffice and Word formats, which could then be printed or delivered electronically for job applications. I believe that the owner of the application is no longer offering it online at this time, but you can see a demo here to get an idea.

        During the development, I found out that changing OpenOffice files was somewhat easier to perform, so I used that instead of editing Word files directly. If the user wanted a Word file, it would be generated with the help of an OpenXML/ODF translator command line tool, and this optional step would take just a second or two.

        I did not use COM, just the selected *.odt templates were decompressed, and the information provided by the candidate was formatted and injected into the "content.xml" of the chosen document, then saved, compressed and renamed back to *.odt. If desired, that file would be converted to *.docx and opened in Word for review. It was a long road to get this working smoothly, so if you really want to do this, be prepared to spend a long time with research.



        • #5
          Huh - I'm familiar with The Australian Résumé Writer. Have seen it before and played with it in the past. Interesting to know that you were responsible for its development. So would the process you outlined apply with other doc types from the MS suite?( ie. Excel, PowerPoint, etc).


          • #6
            I have never checked if these other Office files use a similar internal format, so I cannot answer this, sorry.



            • #7
              Alternatively you can buy Edraw ActiveX
              ...... integrated into AMS

              Click image for larger version

Name:	Cattura.PNG
Views:	173
Size:	59.6 KB
ID:	303365


              • #8
                thanks to all
                i was able to solve the problem with your help
                i extract my docx contents using zip.extract function
                then, i replace the tags with my values in document.xml in word docx file

                but I've seen a sample before i think is better than above solution :


                • #9
                  Originally posted by herrin View Post
                  Alternatively you can buy Edraw ActiveX
                  ...... integrated into AMS

                  Hi dear friend

                  can you put a simple project for this ActiveX ?
                  where can i download it ?