Bouke / docx-mailmerge

Mail merge for Office Open XML (docx) files without the need for Microsoft Office Word.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nextPage_section template merge does not correctly handle merge fields in document footers

briantkatch opened this issue · comments

Expected Behavior

When a merge field is in a document footer, it should be correctly filled when using section merging with the merge_templates method of a MailMerge object. This occurs when performing a 'real' merge using MS Word.

Current Behavior

These fields are erased when merging in this mode. This does not occur when performing a merge using MS Word.

Steps to Reproduce (for bugs)

I have put together a repository with test data and a template at https://github.com/briantkatch/python-mailmerge-issue.

When performing a 'real' mail merge in MS Word using the included template and CSV file (which contains identical test data to the Python script), Word automatically uses section breaks (without the user having to specify as such) to add different content to each footer per the merge data source. View the expected_result.docx file with Word set to show all invisible markup to see what I mean.

When you run the Python script (make sure you've installed the mailmerge module from master first), which takes the same template and uses identical test data, to do the merge, the fields in the footer are erased, despite explicitly setting section merge mode.

Context

In my actual document template, I have a footer that uses a barcode font to have a control number field in the footer that is populated during mail merge. Given the layout of this document it would be a significant nuisance to re-arrange it so this field is not in the footer.

Your Environment

  • Python version: Python 3.6.4 on macOS Sierra (10.12.6)
  • docx-mailmerge version: latest master (6900b68 at time of writing)
  • MS Word version: Microsoft Word for Mac 16.10

I echo the same problem with latest master at the time of writing.
And indeed same issue for header and footer.