We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Inserting a table with mailmerge

is it possible to insert a table created inn docx-format to a mailmerge field? Or is there a another way to insert tables with mailmerge?


Please try using the following code. Hope, this helps.

Document doc = new Document("D:\\Temp\\in.docx");
Document subDoc = new Document("D:\\Temp\\input.docx"); // this .docx contains only the Table

doc.getMailMerge().setFieldMergingCallback(new HandleMergeField());
doc.getMailMerge().execute(new String[] { "mf" }, new Object[] { subDoc });

private static class HandleMergeField implements IFieldMergingCallback {
    public void fieldMerging(FieldMergingArgs args) throws Exception {
        if (args.getFieldName().equals("mf")) {
            DocumentBuilder builder = new DocumentBuilder(args.getDocument());

            builder.insertDocument((Document) args.getFieldValue(), ImportFormatMode.USE_DESTINATION_STYLES);

    public void imageFieldMerging(ImageFieldMergingArgs args) {