0

I'm trying to populate a Word document in Python with docx-mailmerge. Everything was working fine, but after some editing at home on another computer with another version of Word, my script gives an error at the line:

document = MailMerge(template) 

Error:

document = MailMerge(template)

File "C:\Python27\lib\site-packages\mailmerge.py", line 79, in __init__
parent.remove(child)
File "src\lxml\lxml.etree.pyx", line 950, in lxml.etree._Element.remove 
(src\lxml\lxml.etree.c:50327)
ValueError: Element is not a child of this node.

What does this mean?

martineau
  • 119,623
  • 25
  • 170
  • 301
Joost
  • 480
  • 1
  • 5
  • 15
  • what is template ? – Haifeng Zhang May 30 '17 at 21:30
  • A Word file (*.docx) – Joost May 30 '17 at 21:46
  • 1
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. – Prune May 30 '17 at 21:50

2 Answers2

0

You didn't give us any run-time context, but this message simply informs you that the object lmxl.etree at the given line, has no attribute (data field) called Element. etree apparently exists, but it obviously is not of the expected type or structure. It's possible that the tree node isn't fully-formed somehow: a spreadsheet cell is empty, or has a seriously invalid value.

Prune
  • 76,765
  • 14
  • 60
  • 81
0

I had similar problem with docx-mailmerge. It turned out that in my .docx file curly brackets on a single mergefield were not at the same row, so mailmerge could not detect the merge field properly.

Example: { MERGEFIELD Foo                                                                   }

Fixed: { MERGEFIELD Foo }