Page 1 of 1

Fill out doc form fields

PostPosted: Fri Dec 07, 2012 8:42 am
by StefanLindner
We have a lot of old 2003 etc. .doc word files. They contain form fields (FORMFIELD objects). When we save them as docx files they still contain these form fields.
Now we try to process them with docx4j to fillout these names fileds with string values. We try FieldsMailMerge from docx4j examples but the content of the form fiels stays empty. After a lot of research we stuck at the same point like http://stackoverflow.com/questions/1167 ... -with-java

Is there any example or documentation for doing this? Or is there any simple documentation for en users how to create word 2007/2010 documents with formfields that cna be processed with java?

Re: Fill out doc form fields

PostPosted: Fri Dec 07, 2012 9:02 pm
by jason
It wouldn't take much to adapt the existing code in docx4j to process a field of the form:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:p >
      <w:r>
        <w:fldChar w:fldCharType="begin">
          <w:ffData>
            <w:name w:val="textfieldbookmark"/>
            <w:enabled/>
            <w:calcOnExit w:val="0"/>
            <w:textInput>
              <w:default w:val="textfield1"/>
            </w:textInput>
          </w:ffData>
        </w:fldChar>
      </w:r>
      <w:r>
        <w:instrText xml:space="preserve"> FORMTEXT </w:instrText>
      </w:r>
      <w:r>
        <w:fldChar w:fldCharType="separate"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:noProof/>
        </w:rPr>
        <w:t>textfield1</w:t>
      </w:r>
      <w:r>
        <w:fldChar w:fldCharType="end"/>
      </w:r>
    </w:p>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Alternatively you could use docx4j (or perhaps VBA/macros) to convert these to MERGEFIELD or to data bound content controls (org.docx4j.model.datastorage.migration.FromMergeFields can convert MERGEFIELDs to content controls; it could be made to convert these types of fields as well).