Free Support Forum - aspose.com

Inserting a space between Merge fields

Hi, when I try to insert a space between two merge fields a get a tab instead of a blank space.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

But if I insert any other character it works fine. The problem is very simple I must insert a space

between NAME and SURNAME. Thank you, my best regards.

Luciano

See the code below.

builder.MoveToDocumentEnd()

builder.Document.DefaultTabStop = 144

builder.Writeln(Chr(10) & Chr(13) & "Company " & ControlChar.Tab & ControlChar.Tab & "CUSTOMER")

builder.InsertField("MERGEFIELD ENPLOYEE \* MERGEFORMAT", "")

builder.Write(ControlChar.Tab & ControlChar.Tab)

builder.InsertField("MERGEFIELD NAME \* MERGEFORMAT", "")

builder.InsertField("MERGEFIELD SURNAME \b “” ”” \* MERGEFORMAT", "")

The result is the following:

NAME SURNAME

Instead of:

NAME SURNAME

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

Thanks for your request. I think that you can try using the following code.

Dim doc As Document = New Document()

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

builder.MoveToDocumentEnd()

builder.Document.DefaultTabStop = 144

builder.Writeln(Chr(10) & Chr(13) & "Company " & ControlChar.Tab & ControlChar.Tab & "CUSTOMER")

builder.InsertField("MERGEFIELD ENPLOYEE \* MERGEFORMAT", "«ENPLOYEE»")

builder.Write(ControlChar.Tab & ControlChar.Tab)

builder.InsertField("MERGEFIELD NAME \* MERGEFORMAT", "«NAME»")

builder.Write(" ") 'insert a blank space

builder.InsertField("MERGEFIELD SURNAME \* MERGEFORMAT", "«SURNAME»")

doc.Save("out.doc")

Hope this helps.

Best regards.

Hi, I have already tried this, but nothing changed. The weird thing is that: if afterwards I open the resulting doc by WORD and I will insert a space between NAME and SURNAME it gets it as if it was a tab. Thank you again for helping me. Regards

Luciano

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

Could you please attach your document? I will investigate this problem and provide you more information.

Best regards.

Hi, when I was getting ready, by WORD, the sample for you, I pushed a carriage return after the last field (SURNAME) and I saw that the field was shifted to the left in its correct position. So I changed the code in the way that you can see below and it works fine. In any case, if you want deeply investigate about this problem, you have the document attached.

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

Thank you regards.

Luciano

Dim builder As DocumentBuilder = New DocumentBuilder(dstDoc)

builder.MoveToDocumentEnd()

builder.Document.DefaultTabStop = 144

builder.Writeln(Chr(10) & Chr(13) & "Per Confesercenti " & ControlChar.Tab & ControlChar.Tab & "l'Utente")

builder.InsertField("MERGEFIELD FUNZIONARIO \* MERGEFORMAT", "<>")

builder.Write(ControlChar.Tab & ControlChar.Tab)

builder.InsertField("MERGEFIELD COGNOME \* MERGEFORMAT", "<>")

builder.Write(" ")

builder.InsertField("MERGEFIELD NOME \* MERGEFORMAT", "<NOME>>")

builder.Write(Chr(10) & Chr(13))

Here is the file

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

Thanks for additional information. I figured out the problem. This occurs because thre is section break directly after merge field. You just should do the following.

builder.InsertField("MERGEFIELD NOME \* MERGEFORMAT", "<NOME>>")

builder.Writeln()

Best regards