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

Free Support Forum - aspose.com

Leading Tab in Merge Field Dropped

We have a mergefield where the data in the merge field has a leading tab. This tab seems to get dropped, other tabs in the field are fine, it is just the leading tab.

This seems to mainly be a problem with consecutive merge fields on the same line.

Something like this
{Mergefield 1}{Mergefield 2}

When Mergefield 2 contains a leading tab it is ignored.

Is this a known issue?

We are at the latest version as of 6/15/18.


Adam R Aitken


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Aspose_Example.zip (23.0 KB)

Here is the example console add with inputdocument and outputdocument.



Thanks for sharing the detail. We are working over your query and will get back to you soon.


Thanks for your patience. Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using MS Word, you will get the same output. This is expected behavior. However, you can achieve your requirement by implementing IFieldMergingCallback interface as shown below.

MergeInputDS ds = new ConsoleApplication28.MergeInputDS();
ds.Merge.AddMergeRow("AROM", "\tPrev R.\tPrev L.\tRight\tLeft");
Aspose.Words.Document doc = new Aspose.Words.Document(ms);
doc.MailMerge.FieldMergingCallback = new HandleMergeField();

private class HandleMergeField: IFieldMergingCallback
    /// <summary>
    /// This is called when merge field is actually merged with data in the document.
    /// </summary>
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
        if (e.DocumentFieldName.Equals("AROM_Caption"))
            DocumentBuilder builder = new DocumentBuilder(e.Document);

            e.Text = "";

    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
        // Do nothing.

WordVsAspose.png (44.7 KB)

Attached is a picture showing the difference between the Word Mail merge and the Aspose Mail merge.

In the merge template we had the following:


The data that was entered was “AROM” and “\tPrev R.\tPrev L.\tRight\tLeft”.

In the Aspose merge the leading tab (\t) is dropped. We are only seeing this happen when 2 merge fields are right next to each other as in the example. This is also happening in the consoleapp that we provided up above.




Thanks for sharing the detail. The MailMerge.TrimWhitespaces property trimmed the trailing and leading white spaces. The default value of this property is true. You can set its value to false to get the desired output.

Aspose.Words.Document doc = new Aspose.Words.Document(ms);
doc.MailMerge.TrimWhitespaces = false;