Page 1 of 1

"Hello, world!" with form fields

PostPosted: Wed Mar 06, 2019 6:08 am
by 6cef
I need the simplest possible example using form fields to create a document from a template.

I've looked at a number of examples and none of them seem to do exactly what I need.

I will have complete control of the template and the fields, so I can modify the template as needed, including knowing and being able to manipulate field names and styles.

Thanks for any help!

Serious replies only. :)


Re: "Hello, world!" with form fields

PostPosted: Tue Mar 12, 2019 5:04 pm
by jason
Are you asking how to programatically create a document/template with MERGEFIELDs in it, or given such a document, how to fill it?

It sounds like the latter ... is the FieldsMailMerge sample not what you want?

Re: "Hello, world!" with form fields

PostPosted: Fri Mar 15, 2019 6:13 am
by 6cef
That's correct: FieldsMailMerge is not what I'm looking for.

I'm looking for the code that will properly fill out a Word form field. Not a merge field; not a regex replacement of ${Some field}.

I'm looking for code that, given a dotx file with form fields in it, will be able to create a new document based on that template with the form fields properly filled out.

Example dotx file attached.

Re: "Hello, world!" with form fields

PostPosted: Fri Mar 15, 2019 9:42 am
by jason
You are using the wrong terminology.

Your document contains:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
          <w:id w:val="-1063023568"/>
            <w:docPart w:val="DefaultPlaceholder_-1854013440"/>
            <w:t>This is a form field.</w:t>
Parsed in 0.001 seconds, using GeSHi

That's a content control, not a form field.

docx4j has strong support for content control data binding. See further

Re: "Hello, world!" with form fields

PostPosted: Sat Mar 16, 2019 3:29 am
by 6cef

That's great, thanks for the tip! I'll look this over and see what I can figure out.