Showing box rather than newline in merge field

Hello,

I have been a long time user of Aspose Words and have different versions running on our applications.

I have updated one of my apps to Aspose Words 17.2.0.0

I now have an issue in that when trying to populate a merge field that contains a newline, the following appears:

First line<>Second line

Rather than

First line
Second line

The VB code is as follows: str = “First line” & vbLf & “Second line”

This works as expected for older versions such as 14.4.0.0

Any assistance would be greatly appreciated

@joedigiulio

Thanks for your inquiry. We have tested the scenario with Aspose.Words for .NET 17.10 and unable to notice the reported issue. Please share your sample console application along with your template file as ZIP file here. We will look into it and will guide you accordingly.

Dim inputpath As String = ("input.docx")
Dim document As New Document(inputpath)
Dim firstline As String = "hello"
Dim secondline As String = "World"
Dim multiline As String = firstline & vbLf & secondline

document.MailMerge.Execute(New String() {"Name", "Name1"}, New Object() {multiline, "John snow"})
document.Save("Output_1710.docx")

Hello,

Thank you for your reply.

Based on what you have told me, I can now provide more information.

The problem is occurring when I am using IFieldMergingCallback.FieldMerging to change the color of the text.

The text needs to display as red, orange or green depending on flags set.

If I bypass setting the colour then it works as expected.

sample code is below:

If e.FieldName.Equals(“DiaHbaAch”) Then
'Here you can modify code according to your requirements.
mBuilder.MoveToMergeField(e.FieldName)
run.Text = e.FieldValue
If bolDiaHbaAtTarget = True Then
font.Color = System.Drawing.Color.Green
End If
If bolDiaHbaNotAtTarget = True Then
font.Color = System.Drawing.Color.Red
End If
If bolDiaHbaNotAssessed = True Then
font.Color = System.Drawing.Color.Orange
End If
font.Size = 10.5
mBuilder.InsertNode(run)
End If

@joedigiulio

Thanks for your feedback. As stated above please share a sample console project(without compilation error) along with the word template. It will help us to investigate and address your issue exactly.

Hello,

Please find sample console project highlighting the problem.

'If you comment out the following line the vbLf will work
document.MailMerge.FieldMergingCallback = New HandleMergeField()

Sorry file attached App.zip (23.3 KB)
Input.zip (109.0 KB)

@joedigiulio

Thanks for sharing the sample project. I have tested the scenario and unable to notice the box instead of new line, but vbLf is not rendering as new line in both 17.10 and 14.4. You may use ControlChar.LineBreak, it gives expected results in both 17.10 and 14.4.

Dim multiline As String = firstline & ControlChar.LineBreak & secondline

Hello,

Thank you for your response.

I can confirm that this has resolved the problem that I was having.

Thank you once again for your prompt responses and advice.