I am working with mergeFields in a docx document.
I am trying to replace a mergeField in a paragraph with a certain font, Century Gothic size 10. To do this I'm using the latest version of docx4j, 2.8.1.
After the mergeField is replaced the paragraph isn't fully Century Gothic size 10 anymore. The first style, stops after the replaced mergeField, is in Century Gothic size 10. The second part, start immediate after the replaced mergedField, is in Times New Roman size 11.
Is this normal behaviour (not implemented yet), or a bug.
I have written a unit test on the MailMerger class. I attached the file, that I used for unit testing (mailmerge.docx). The output is also attached.
- Code: Select all
public class LocalMailMergerTest {
/** The Constant TEMP_DIR. */
private static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
/** The Constant SEPARATOR. */
private static final String SEPARATOR = System.getProperty("file.separator");
/** The Constant INPUT_FILE_PATH. */
private static final String INPUT_FILE_PATH = "/mailmerge.docx";
/** The Constant OUTPUT_FILE_PATH. */
private static final String OUTPUT_FILE_PATH = "/output.docx";
@Test
public void testMailMerger() throws WordIntegrationZipFileException, Docx4JException {
InputStream bin = null;
bin = ClassLoader.class.getResourceAsStream(INPUT_FILE_PATH);
LoadFromZipNG loader = new LoadFromZipNG();
OpcPackage opcPackage = loader.get(bin);
List<Map<DataFieldName, String>> fieldsList = new ArrayList<Map<DataFieldName, String>>();
Map<DataFieldName, String> fieldsMap = new HashMap<DataFieldName, String>();
fieldsMap.put(new DataFieldName("KTESS"), "880");
fieldsList.add(fieldsMap);
WordprocessingMLPackage result = MailMerger.getConsolidatedResultCrude(
(WordprocessingMLPackage) opcPackage, fieldsList);
SaveToZipFile saver = new SaveToZipFile(result);
saver.save(TEMP_DIR + SEPARATOR + OUTPUT_FILE_PATH);
}
}
Thx!
Timothy