Tabs in merge data - data starting with a tab will get the tab removed when merging

Hi, I’d like to know if there is any trimming of values when the mail merge is performed.
My scenario is this:
I have a Word template for letters with a header section, some transaction lines and a total section.
It’s one row in the data source. The data for the transaction lines of one letter are put into ONE single data field, formatted with line breaks and tabs. This data field is merged into a merge field called “Line1”.
The word template has suitable tab settings on the line containing the “Line1” merge field to make the data show in a nice tabbed layout.

This works perfectly except for the first line of the “line1” data.
The data happens to be laid out so that the first character of each line is a tab.
The first tab in the data field is being stripped off by the mail merge. I’ve checked the data and the tab is definitely in there when I have loaded the data into my datatable.

I did a few tests and it seems that the tab and any other whitespace I add in front of it is trimmed off automatically. If I cheat with the loaded data and add a printable character (a dot) in front, the tab is preserved and the layout is right. Except for the extra dot at the start of the first line, of course…

I’ve zipped the template document (it’s a .doc not a .docx) and an xml file showing sample data.
template doc and xml data example.zip (12.0 KB)
The “131” file is where I’ve added a dot in the data source and everything lines up nicely.
The “130” file shows the problem when there’s nothing in front of the first tab.
potenar131.docx (27.4 KB)
potenar130.docx (27.4 KB)

Is there any way of preventing this from happening? I don’t want to add random dots to my documents if it can be avoided :slight_smile:

Thanks,
Karin

@KarinMX,

In data file, instead of dot, you can place Enter character after <Line1>. Please check this data file (DataFiletest-tenar-3 - modified.zip (3.0 KB)) and try running the following C# code:

Document doc = new Document("C:\\template doc and xml data example\\tenar-example.doc");

DataSet dataSet = new DataSet();
dataSet.ReadXml("C:\\template doc and xml data example\\DataFiletest-tenar-3.xml");

doc.MailMerge.Execute(dataSet.Tables[0]);

doc.Save("C:\\template doc and xml data example\\21.9.docx");

Yes, that works too. I had tried LF alone, but not CR+LF.

But it also alters the layout by adding an extra blank line.

The task I have been given is to make the Aspose mail merge work “just as Word did” for existing stored mail merge data and template documents. It is essential that the output is as close as possible to what Word produces. It’s the stored record of documents that were actually sent out to clients, but stored as data + template.

I’m not sure what is the best workaround, the dot or the extra line.
And in any case, for me, it’s a workaround. The Aspose mail merge does not behave in the same way as the native Word mail merge.

Thanks :slight_smile:
Karin

I’ve also tried the Word non-breaking space character (ASCII 32). Doesn’t work.
I’m trying of think of anything else that would be invisible, but running out of ideas…

@KarinMX,

For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system with ID WORDSNET-22796. We will further look into the details of this problem and will keep you updated here on the status of linked issue. We apologize for your inconvenience.

1 Like

@KarinMX,

Regarding WORDSNET-22796, it is to update you that we have completed the work on this issue and concluded to close this issue with “not a bug” status.

MS Word’s behavior actually depends on the type of data source. MS Word trims whitespaces from .mdb and does not from .csv.

Aspose.Words trims whitespaces by default. But, this behavior may be adjusted with the Document.MailMerge.TrimWhitespaces option.