Page 1 of 1

Mail merge loses formatting information?

PostPosted: Tue Apr 24, 2012 9:00 pm
by marcin
I'm using docx4j to fill out mergefields in a template document. Unfortunately, the merge process seems to lose a lot of formatting (whether or not the
Code: Select all
\* Mergefield
switch is set). In particular, it always loses text alignment information. This matters, because I want to be able to set the title dynamically.

This is a (decrufted) version of the code I am using:

Code: Select all
import org.docx4j.model.fields.merge.MailMerger;

InputStream body; // assigned elsewhere

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(body);

//mail merge
WordprocessingMLPackage merged = MailMerger.getConsolidatedResultCrude(wordMLPackage, translations_wrapped);


Any suggestions?

I also have a bonus question: is it possible to merge text into a field which contains linebreaks, so that the text shows up on multiple lines after merging?

Re: Mail merge loses formatting information?

PostPosted: Wed Apr 25, 2012 1:04 am
by jason
Please note the limitations documented in the Javadoc:

Code: Select all
* LIMITATIONS:
* - currently only applied to main document part
*   (easily extended)
* - no support for text before (\b) and text after (\f)
*   switches
* - no support for \m and \v switches
* - no support formatting (date/time, numeric, or general),
*   including MERGEFORMAT (which means preserve
*   the formatting of any existing field result)
* - no support for multiple MERGEFIELD in a single
*   instruction (eg MERGEFIELD CoutesyTitle \f " " MERGEFIELD FirstName \f " " MERGEFIELD LastName )


We'd be happy to accept patches addressing any of these.

Re: Mail merge loses formatting information?

PostPosted: Wed Jun 13, 2012 9:54 pm
by sledwich
I am working on this now and I think I can see the cause of the problem.

I am attempting to fix it now, and if Jason feels its safe to commit the change we can get others involed, if there anybody interested in this please do let me know so we can thoroughly test the change.

I have also been working on an enhancement, if the merge field contains new line character to support this too. All going well so far.

Thanks

Re: Mail merge loses formatting information?

PostPosted: Wed Jun 20, 2012 10:29 pm
by jason
Hi, thanks for the heads up.

Re the list of limitations, I'm considering improving "support formatting (date/time, numeric, or general)", but I don't want to duplicate anything you already have in hand.

So could you pls describe the enhancements you are working on?

thanks .. Jason