1

I'm trying to insert a string value that contains leading and trailing whitespaces into a Word document's merge fields using Python docx-mailmerge.

However everytime I do this, the value in the Word file seems to delete that whitespaces.

str_value = "    Hello I'm         John Doe  "

The result I'm trying to achieve in the Word document:

Phrase: "    Hello I'm         John Doe  "

The result I got after using doc.merge(phrase=str_value):

Phrase: "Hello I'm         John Doe"

Is there any way I can make docx-mailmerge to not remove those leading and trailing whitespaces?

AB3
  • 67
  • 6
  • From what you've posted, it seems you're not actually doing a mailmerge - all you're doing is changing the text displayed by various mergefields. You might consider using Word Content Controls instead. – macropod Jun 24 '22 at 11:10

0 Answers0