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

Free Support Forum - aspose.com

Generating merge fields with line breaks

Before we converted to Aspose.Words, our custom merging tool would accept the following merge field definitions with line breaks (\br). Merging with Aspose.Words doesn’t recognize that syntax.

Is there something with which I can replace the \br\ so I can pass a line break to Word?

defendant1 = String.Format("{0}\br\{1}", defendant1, lines(i).ToString.Trim)
defNum = String.Format("({0}", SplitFields(lines(i).ToString.Trim, "(", 1))
defendantNum = String.Format("{0}\br\{1}", defendantNum, defNum)
sectionSymbol = String.Format("{0}\br\{1}", sectionSymbol, singleSectionSymbol)
defendant1_pc = StrConv(defendant1, VbStrConv.ProperCase)

Thank you.
Ward

@wrowell1 You can use line break character "\x000b" or "\v". Please see ControlChar.LineBreak.

Hi Alexey. Thank you for your quick response. I tried both of those (see sample below) but it just incudes the text of the line break characters in the Word document. I need to just insert the line break in my merge field definitions as shown in my code, but neither example seems to work. Thank you again!

defendant1 = String.Format("{0}\x000b{1}", defendant1, lines(i).ToString.Trim)
defNum = String.Format("({0}", SplitFields(lines(i).ToString.Trim, "(", 1))
defendantNum = String.Format("{0}\x000b{1}", defendantNum, defNum)
sectionSymbol = String.Format("{0}\x000b{1}", sectionSymbol, singleSectionSymbol)

Word Document result with “/v.”:

Code screen shot:

Ward

@wrowell1 Could you please attach you template, output document and full code that will allow us to reproduce the problem? I have tested with a simple template and the following code and line breaks are processed properly:

string[] names = new string[] { "Test" };
string[] values = new string[] { "This is multiline\vtext with soft\vlinebreak" };

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.Execute(names, values);
doc.Save(@"C:\Temp\out.docx");

Here is input and output documents: in.docx (12.0 KB)
out.docx (9.4 KB)

Thank you Alexey. I’m attaching my template.

Ward
CriminalAmendedPretrialSchedulingOrder.docx (31.2 KB)

@wrowell1 Thank you for additional information. Your template also works as expected on my side. Here is the code I used for testing:

string[] names = new string[] { "division", "casenumber", "defendant1", "SS", "order_date" };
string[] values = new string[] { "division\vdivision", "casenumber\vcasenumber", "defendant1\vdefendant1", "SS\vSS", "order_date\vorder_date" };

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.Execute(names, values);
doc.Save(@"C:\Temp\out.docx");

Thanks so much! I’ll test it out on my end. I really appreciate your help.

Ward

1 Like

Hi Alexey. I’m afraid I’m still getting the “\v” in the merge document instead of a line break. I’m attaching both my merged Word document and the VB code that’s used to generate the merge field names and values. On line 67 of the text file is where I’ve place the “\v” in between the values. Maybe you’ll see something that I’m doing wrong.

Thanks again.

322cr00030N_final (9).docx (26.6 KB)

MergeDocumentCode.docx (20.2 KB)

@wrowell1 Thank you for additional information. Escape sequences does not work in VB strings. You should use ControlChar.LineBreak, like shown in the following code:

Dim names As String() = New String() {"Test"}
Dim values As String() = New String() {"This is multiline" + ControlChar.LineBreak + "text with soft" + ControlChar.LineBreak + "linebreak"}

Dim doc As Document = New Document("C:\Temp\in.docx")
doc.MailMerge.Execute(names, values)
doc.Save("C:\Temp\out.docx")

Thank you again! This worked perfectly.

1 Like