Inserting altChunk into docx template

Home Forums WordprocessingML Inserting altChunk into docx template

This topic contains 1 reply, has 1 voice, and was last updated by  xmedeko 4 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7946

    xmedeko
    Participant

    Hi Eric,
    our app (Electron.js) generates HTML and our users import it manually into their Word documents. We want to automatize the process. A user prepares a template docx with some mark and we insert the HTML into the DOCX where the mark is.

    Our current idea is let the user put into her template the MERGEFIELD, e.g. MERGEFIELD ReplaceHere field and replace it with the altChunk element. We would like to use a pure JavaScript solution if possible, i.e. some JS XML parser or maybe your outdated openxmlsdkjs. So far, I have hit two problems:

    1. The MERGEFILD text is not always easy to find, because it may be split into multiple w:instrText elements.
    2. The altChunk has to be a sibling to <w:p> element so we may place it in a wrong place. Probable solution is to find nearest <w:p> parent and replace it?
    3. If the HTML contains some bigger image, then it’s not shown. Word shows the layout of inserted HTML overlaps with the original docs content.

    Do you think is inserting HTML doable this way? Do you know some better way how to make some user-made markup in DOCX and insert/import HTML there?

    Thanks
    Andy

    #7947

    xmedeko
    Participant

    I’ve just found that content control <w:std> is more appropriate for templating than MERGEFIELD. So, the problem 1. solved. The <w:std> is easier to find. I am just not sure how to use <w:alias>, <w:tag> and content control text to be convenient for the users who would create the DOCX templates.

    And finally found this blog with the solution https://blogs.msdn.microsoft.com/brian_jones/2008/12/08/the-easy-way-to-assemble-multiple-word-documents/

    • This reply was modified 4 years, 8 months ago by  xmedeko.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.