Free Support Forum - aspose.com

MailMerge with different heading style

Hello,

I’m creating a word document with mailmerge.
I’ve to apply to a specific field different heading style (h1, h2, h3, ecc) base on parameter. I’ve tried to insert some html tag ("

" for example) but isn’t working.

Someone can help me?

Hi Alessandro,


Thanks for your inquiry. You can achieve this by implementing IFieldMergingCallback interface. Please see following example:

private class HandleMergeFields :
IFieldMergingCallback

{

void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)

{

if (e.DocumentFieldName.StartsWith("<h1"))

{

DocumentBuilder builder = new DocumentBuilder(e.Document);

builder.MoveToMergeField(e.DocumentFieldName);

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.Write((string)e.FieldValue);

e.Text = "";

}

}

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)

{

// Do nothing.

}

}


http://www.aspose.com/docs/display/wordsnet/How+to++Apply+Custom+Formatting+during+Mail+Merge

I hope, this helps.

Best regards,