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

Free Support Forum - aspose.com

Problem with font in field values in a Word document

Hello,

I’ve some problems with fonts changed in some paragraphs at the places of field values. What is strange, that it’s changed for only a part of the text of a field value. In my document I’ve got a “field1” which is replaced by a value within command doc.getMailMerge().executeWithRegions(). The value of field will be partially in good format and the rest will be in another one. For the value “Bank Transfer for regular payment with no RIB”, the word “Bank” will have the good font “Times New roman” and the rest will be with the “Clibri(body)” font.

To resolve this problem, I ‘tried to change all the “runs” of my document with explicit font name and size, it changed the font for all runs but not for the parts in “Colibri” font. When I debug and watch the font of every run in the document I see my field value in a good format. It seems like Aspose changes the format when it saves the document.

Thanks in advance

Hello

Thanks for your request. Could you please attach your template here for testing? I will check the problem and provide you more information.

Best regards,

There are two templates: the main template : MOD_CLIENT_01.docx and another one : Msg_paiement_en.docx. Bookmarks from the second document are used to be inserted in the first document.

Thank you

Best regards

Hello

Thanks for your request. I cannot reproduce this problem on my side using the latest version of Aspose.Words for Java 10.5.0. Could you please attach simplified code which will allow me to reproduce the problem on my side? I will check it and provide you more information.

Best regards,

Hello,

Thank you for your quick answers. May be the problem was coming from my Word template. I’ve recreated this one and it works well for the moment.

Sincerely

Hi

It is perfect, that you already found the way to resolve the problem. If you need more assistance, I will be glad to help you.

Best regards,

Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Unfortunately, I have the same problem once more. My font changes in the middle of the text inserted as a value of a field. This text comes from another document and I think the problem occurs when I use the method importNode(bkmrk_para,true,ImportFormatMode.USE_DESTINATION_STYLES). I’ve tried also ImportFormatMode.KEEP_SOURCE_FORMATTING with the same result.

Here, you can find the simplified code that replaces the field on I get the problem:

Taken from IFieldMergingCallback

public void fieldMerging(FieldMergingArgs args) throws Exception

{

if ("EXT_MSGPMNT".equals(args.getFieldName()))

{

insertMsgPmntParagraph(args,getPaiementMsg(args),false);

parent_doc.getMailMerge().executeWithRegions(new NoticeClientDataSource(notice_data.subList(args.getRecordIndex(),args.getRecordIndex()+1),"ReglementMsg",langue));

}

}

private void insertMsgPmntParagraph(FieldMergingArgs args,String bkmrk_name,

boolean isAttachParagraph) throws Exception{

Bookmark bkmrk=child_doc.getRange().getBookmarks().get(bkmrk_name);

if (bkmrk==null)

return;

Node bkmrk_para=bkmrk.getBookmarkStart().getParentNode();

CompositeNode parent_node=args.getField().getStart().getParentNode();

CompositeNode dstNode=(CompositeNode)parent_doc.importNode(

bkmrk_para,true,ImportFormatMode.USE_DESTINATION_STYLES);

insertParagraphElements(args.getField().getStart().getPreviousSibling(),dstNode);

args.getField().remove();

}

private void insertParagraphElements(Node elem_after,CompositeNode para_from) throws Exception{

Node elem_after_local=elem_after;

Node child;

Node next_child=para_from.getFirstChild();

while(next_child!=null){

child=next_child;

next_child=next_child.getNextSibling();

elem_after.getParentNode().insertAfter(child,elem_after_local);

elem_after_local=child;

}

}

Taken from IMailMergeDataSource

protected boolean getValue_Payement(String fieldName, Object[] fieldValue) throws Exception{

if (fieldName.equals("TYPEPAIEMENT"))

{

if (notice_data.get(mRecordIndex).getTypepaiement()==null)

return false;

fieldValue[0] = notice_data.get(mRecordIndex).getTypepaiement().getTmplibelle();

return true;

}

else

{

fieldValue[0] = null;

return false;

}

}

In the attached files, you’ll find two templates and the file after merging. As you can see, the problem occurs in the field TYPEPAIEMENT.

Thanks

Hello

Thanks for your inquiry. Could you please provide me full code which will allow me to reproduce the problem on my side? Also, which version of Aspose.Words you are using?

Best regards,