Package org.docx4j.model.fields.merge
Class MailMerger
java.lang.Object
org.docx4j.model.fields.AbstractMerger
org.docx4j.model.fields.merge.MailMerger
- Direct Known Subclasses:
MailMergerWithNext
Perform a mail merge.
Instance values are merged into a docx containing
MERGEFIELD to produce output docx made up of
a copy of the input docx for each collection of
input values.
The output can be a single docx, or multiple docx.
If you choose single docx, there are two ways to
do this:
One is using MergeDocx, which will ensure each
constituent "document" doesn't affect the neighbouring
ones (eg numbering will restart).
The other is the "poor man's" approach, which
puts them together, and just hopes for the best.
Images and hyperlinks should be ok. But numbering
will continue, as will footnotes/endnotes.
From 3.0, there is some support for formatting switches
(date/time, numeric, and general), and basic
support for MERGEFORMAT.
LIMITATIONS:
- no support for text before (\b) and text after (\f)
switches
- no support for \m and \v switches
- no support for multiple MERGEFIELD in a single
instruction (eg MERGEFIELD CoutesyTitle \f " " MERGEFIELD FirstName \f " " MERGEFIELD LastName )
- Author:
- jharrop
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.docx4j.model.fields.AbstractMerger
AbstractMerger.FormTextFieldNames -
Field Summary
Fields inherited from class org.docx4j.model.fields.AbstractMerger
fieldFate, input -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringextractInstr(List<Object> instructions) static WordprocessingMLPackagegetConsolidatedResultCrude(WordprocessingMLPackage input, List<Map<DataFieldName, String>> data) Deprecated.static WordprocessingMLPackagegetConsolidatedResultCrude(WordprocessingMLPackage input, List<Map<DataFieldName, String>> data, boolean processHeadersAndFooters) Deprecated.protected static StringgetDatafieldNameFromInstr(String instr) Get the datafield name from, for example <w:instrText xml:space="preserve"> MERGEFIELD Kundenstrasse \* MERGEFORMAT </w:instrText> or <w:instrText xml:space="preserve"> MERGEFIELD Kundenstrasse</w:instrText>static voidperformMerge(WordprocessingMLPackage input, Map<DataFieldName, String> data, boolean processHeadersAndFooters) Deprecated.performOnInstance(List<Object> contentList, Map<DataFieldName, String> datamap, AbstractMerger.FormTextFieldNames formTextFieldNames) protected static voidsetFormFieldProperties(FieldRef fr, String ffName, String ffTextInputFormat) static voidsetMERGEFIELDInOutput(MailMerger.OutputField fieldFate) Deprecated.Methods inherited from class org.docx4j.model.fields.AbstractMerger
canonicaliseStarts, getConsolidatedResultCrude, getTextInsideContent, performMerge, recursiveRemove, removeSimpleField, setOutputField
-
Constructor Details
-
MailMerger
-
-
Method Details
-
getConsolidatedResultCrude
@Deprecated public static WordprocessingMLPackage getConsolidatedResultCrude(WordprocessingMLPackage input, List<Map<DataFieldName, String>> data) throws Docx4JExceptionDeprecated.A "poor man's" approach, which generates the mail merge results as a single docx, and just hopes for the best. Images and hyperlinks should be ok. But numbering will continue, as will footnotes/endnotes.- Parameters:
input-data-- Returns:
- Throws:
Docx4JException
-
getConsolidatedResultCrude
@Deprecated public static WordprocessingMLPackage getConsolidatedResultCrude(WordprocessingMLPackage input, List<Map<DataFieldName, String>> data, boolean processHeadersAndFooters) throws Docx4JExceptionDeprecated.A "poor man's" approach, which generates the mail merge results as a single docx, and just hopes for the best. Images and hyperlinks should be ok. But numbering will continue, as will footnotes/endnotes. [Advert:] If this isn't working for you, the commercial Enterprise Edition of docx4j (MergeDocx component) will solve your problems.- Parameters:
input-data-processHeadersAndFooters- process headers and footers in FIRST section only. If you have multiple sections in your input docx, performMerge is a better approach- Returns:
- Throws:
Docx4JException
-
performMerge
@Deprecated public static void performMerge(WordprocessingMLPackage input, Map<DataFieldName, String> data, boolean processHeadersAndFooters) throws Docx4JExceptionDeprecated.Perform merge on a single instance. This is the best approach, if your input has headers/footers in multiple sections. If you are using MergeDocx, you can use that to join the instances into a single docx. WARNING: The input docx will be modified, so input a copy if that is a problem. This is left to the user, since that can potentially be more efficient, than doing it here.- Parameters:
input-data-processHeadersAndFooters-- Throws:
Docx4JException
-
performOnInstance
protected List<Object> performOnInstance(List<Object> contentList, Map<DataFieldName, String> datamap, AbstractMerger.FormTextFieldNames formTextFieldNames) throws Docx4JException- Specified by:
performOnInstancein classAbstractMerger- Throws:
Docx4JException
-
getDatafieldNameFromInstr
Get the datafield name from, for example <w:instrText xml:space="preserve"> MERGEFIELD Kundenstrasse \* MERGEFORMAT </w:instrText> or <w:instrText xml:space="preserve"> MERGEFIELD Kundenstrasse</w:instrText> -
extractInstr
-
setMERGEFIELDInOutput
Deprecated.What to do with the MERGEFIELD in the output docx. Default is REMOVED. KEEP_MERGEFIELD will allow you to perform another merge on the output document. The AS_FORMTEXT options convert the MERGEFIELD to a FORMTEXT field. This is convenient if you want users to be able to edit the field, where editing is restricted to forms.- Parameters:
fieldFate-
-
setFormFieldProperties
-