Page 1 of 1

Convert MailMerge document to "content controls"

PostPosted: Thu Feb 05, 2015 4:57 am
by jberk
I have a docx file created using word and filled with mail merge fields (by non-tech users). How do I convert that to use "content controls" so I can dull the pain of mail merge telling me "MailMerger(659) - TODO MERGEFIELD field contained complex instruction". I assume that's MS-Word splitting the merge fields across runs???

when I crack open the xml I see:

Code: Select all
<w:r>
        <w:instrText xml:space="preserve"> MERGEFIELD  Guarantor_1_short_name  \* </w:instrText>
      </w:r>
      <w:r w:rsidRPr="001313F4">
        <w:instrText>MERGEFORMAT</w:instrText>
      </w:r>
      <w:r>
        <w:instrText xml:space="preserve"> </w:instrText>
      </w:r>


Code: Select all
<w:r w:rsidRPr="0004112C">
        <w:rPr>
          <w:color w:val="000000"/>
        </w:rPr>
        <w:lastRenderedPageBreak/> // this appears to be causing issues also?????
        <w:instrText xml:space="preserve">MERGEFIELD "Balance_as_of_Today" </w:instrText>
      </w:r>


if it's not possible or just error prone to convert from a doc with mail merge fields to one using content controls, how does one go about creating a word doc (using word) that makes use of content controls. From what I read, you need to enable "developer" stuff in the ribbon. Is that something designed for a non-tech?

In the end, I just want to do the "submit both" sort of thing and let the user submit the key/value pairs and do a search and replace in the doc....but how do I get from a mail merge doc to one of these "content control" type documents?

Re: Convert MailMerge document to "content controls"

PostPosted: Thu Feb 05, 2015 8:29 am
by jason
1. If you can make a simple test case exhibiting MERGEFIELD issues (one issue per test case), we're interested in fixing them.

2. you can try auto converting from MERGEFIELDs to content controls, with org.docx4j.model.datastorage.migration.FromMergeFields

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        /**
         * @param args
         * @throws Exception
         */

        public static void main(String[] args) throws Exception {

                String inputfilepath = System.getProperty("user.dir")
                                                                        + "/TEST1.docx";

                String outputfilepath = System.getProperty("user.dir")
                                + "/OUT_TEST1.docx";

                WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
               
                FromMergeFields migrator = new FromMergeFields();
                WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn);
               
                SaveToZipFile saver = new SaveToZipFile(pkgOut);
                saver.save(outputfilepath);
               
        }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


3. for authoring documents using content control binding, try http://www.opendope.org/downloads/autho ... /setup.exe or http://www.opendope.org/downloads/OpenD ... ySetup.msi

Alternatively, you can try the older http://www.opendope.org/downloads/autho ... /setup.exe or http://www.opendope.org/downloads/OpenD ... nSetup.msi