Free Support Forum - aspose.com

MailMerge and Carriage Returns

I am trying to send some formatted text to a merge field in a document. The text contains a series of lines of text, each ending with a line break character (ControlChars.Lf in Visual Basic). After the merge, the line feeds have been converted to paragraphs in Word.

I have tried this with

ControlChars.Cr
ControlChars.CrLf
ControlChars.FormFeed
ControlChars.Lf
ControlChars.NewLine

And they all get converted to a paragraph in the merged document.

How can I send just a line feed (soft return) to my merge field?

Thanks

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

Thanks for your request. Please try using ControlChars.VerticalTab. See the following code:

VB

'Open template

Dim doc As Document = New Document("in.doc")

'Create array with field names and values

Dim names As String() = {"myField"}

Dim values As Object() = {"this is first line" & ControlChars.VerticalTab & "This is second line" & ControlChars.VerticalTab & "Third line"}

'Execute mail merge

doc.MailMerge.Execute(names, values)

'Save document

doc.Save("out.doc")

C#

//Open template

Document doc = new Document(@"Test198\in.doc");

//Create array wi field names and values

string[] names = { "myField" };

object[] values = { "this is first line\vThis is second line\vThird line" };

//Execute mail merge

doc.MailMerge.Execute(names, values);

//Save document

doc.Save(@"Test198\out.doc");

Hope this helps.

Best regards.