Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

rewrite to support formatting and nesting fields #103

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8d6aa2e
reimplemented the base docx-mailmerge functionality, support for form…
iulica Mar 4, 2022
245c659
removed IF MergeElement and only update the inner MERGEFIELDS
iulica Mar 5, 2022
f11752a
added support for updateFields setting
iulica Mar 6, 2022
bb9c90c
cleaned up the code, removed support for IF, added implemented auto_u…
iulica Mar 6, 2022
fbcc2bc
more verbose error messages
iulica Mar 7, 2022
3dca645
fixed the complex fields when span over multiple paragraphs
iulica Mar 7, 2022
e7cfef4
complete tests, added a workaround to make tests happy for section ty…
iulica Mar 8, 2022
dd3f592
make more tests happy
iulica Mar 8, 2022
68b1327
make all tests happy
iulica Mar 8, 2022
256cf22
make tests happy
iulica Mar 8, 2022
59f2040
test_merge_template_with_rows
iulica Mar 8, 2022
f3fac1f
formatting tests and framework for easier testing
iulica Mar 8, 2022
783d28c
fixes for nested simple Fields and tests for nested fields
iulica Mar 8, 2022
076e191
added tests for auto fields udpate flag
iulica Mar 8, 2022
78c4f90
test for warnings (removing the warnings from the unittest run), impl…
iulica Mar 9, 2022
e0c9604
changed the documentation to reflect the changes
iulica Mar 9, 2022
a0ca1f6
Update README.rst
iulica Mar 13, 2022
e07d5d3
Update README.rst
iulica Mar 14, 2022
0d10293
Update README.rst
iulica Mar 22, 2022
914f811
Create auto_assign-issues.yml
iulica Mar 22, 2022
53b1b66
publish workflow
iulica Apr 1, 2022
af1a967
Update setup.py for version 0.6.0
iulica Apr 1, 2022
b32bf3b
Updated the package name and removed travis CI
iulica Apr 1, 2022
2e3ad7f
fix install command to docx-mailmerge2
iulica Apr 1, 2022
446c70c
Fixed number formatting when value is None
iulica Apr 5, 2022
c226d9f
refactoring to prepare the NEXT and NEXTIF fields implementation
iulica Apr 5, 2022
d30435d
gitignore
iulica Apr 6, 2022
5d33d00
(failed) test for issue #4
iulica Apr 6, 2022
5c4a5c9
add support for fixing the id duplicates issue #4
iulica Apr 6, 2022
443725b
Wish list update
iulica Apr 8, 2022
e53c4cc
added support for test output docx instead of temporary file for debu…
iulica Apr 15, 2022
f8e699c
added an workaround for IF fields containing text values with spaces …
iulica Apr 15, 2022
b12c7c0
added support for apostrophes for currency thousand separators with t…
iulica Apr 15, 2022
4f1190d
implemented date formatting support
iulica Apr 15, 2022
3740614
Release 0.6.2. Added support for Date formatting. Issues #5 #57
iulica Apr 16, 2022
e0c8e9a
implemented NEXT field #4
iulica Apr 16, 2022
bd7175c
fixed NEXT field #4
iulica Apr 18, 2022
55ce8ca
Update TODO list
iulica Apr 20, 2022
6b80124
Update README.rst
iulica Dec 18, 2022
5b1b69a
prepare release 0.6.3
iulica Oct 12, 2023
4945f33
added footnotes+xml to content_types_part
402Martin Oct 16, 2023
7939ebe
Merge pull request #13 from 402Martin/master
iulica Oct 16, 2023
3e45bf0
Revert "Added content type footnotes+xml so mail merge fields are sup…
iulica Oct 16, 2023
edbbac3
Merge pull request #14 from iulica/revert-13-master
iulica Oct 16, 2023
1e6fc8a
Adds test for merge footnotes
iulica Oct 24, 2023
1e256e0
adding support for endnotes and macro enabled documents
iulica Oct 24, 2023
4a313a0
Refactored MergeField class.
iulica Oct 26, 2023
3cbc7f2
Added support for keeping fields in the document.
iulica Oct 27, 2023
a57da5c
prepare release 0.7.0
iulica Oct 27, 2023
22dc108
Refactor duplicate_id_map to its own class UniqueIdsManager
iulica Nov 9, 2023
4ddc603
Added support for header/footer for merge_templates #17
iulica Nov 10, 2023
dae81c3
prepare v0.8.0
iulica Jan 16, 2024
9fb68e5
Update README.rst
iulica Jan 18, 2024
dc42458
Update README.rst
iulica Jan 23, 2024
42dc54d
ruffed
iulica Jul 19, 2024
7338d79
Added failed test for multiple tables with the same anchor
iulica Jul 19, 2024
544680b
Fix case where multiple table contain the same anchor. Issue #24
iulica Jul 19, 2024
f02a517
setup version 0.8.1
iulica Jul 19, 2024
1d2ad75
fix for empty fields, #25
iulica Sep 19, 2024
51a8db7
add test for empty field #25
iulica Sep 19, 2024
02cf82e
setup version 0.8.2
iulica Sep 19, 2024
d7206dc
fix for python 3.7
iulica Sep 27, 2024
f2f2a82
setup version 0.8.3
iulica Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactoring to prepare the NEXT and NEXTIF fields implementation
  • Loading branch information
iulica committed Apr 5, 2022

Verified

This commit was signed with the committer’s verified signature.
ewbankkit Kit Ewbank
commit c226d9ff383516bbca501acce5a61ea25f9da3e2
34 changes: 25 additions & 9 deletions mailmerge.py
Original file line number Diff line number Diff line change
@@ -386,6 +386,7 @@ def __init__(self, root, separator):
self._last_section = None # saving the last section to add it at the end
self._body = None # the document body, where all the documents are appended
self._body_copy = None # a deep copy of the original body without ending section
self._current_body = None # the current document body where all the changes are merged
self._prepare_data(separator)

def _prepare_data(self, separator):
@@ -434,23 +435,35 @@ def _prepare_data(self, separator):
r = etree.SubElement(self._separator, '{%(w)s}r' % NAMESPACES)
nbreak = etree.SubElement(r, '{%(w)s}br' % NAMESPACES)
nbreak.set('{%(w)s}type' % NAMESPACES, sep_type)


def prepare(self, create_new_body=True, first=False):
""" prepares the current body for the merge """
if create_new_body:
assert self._current_body is None
# add separator if not the first document
if not first:
self._body.append(deepcopy(self._separator))
self._current_body = deepcopy(self._body_copy)

def merge(self, merge_data, row, first=False):
# add separator if not the first document
if not first:
self._body.append(deepcopy(self._separator))
""" Merges one row into the current prepared body """

body = deepcopy(self._body_copy)
merge_data.replace(body, row)
for child in body:
self._body.append(child)
merge_data.replace(self._current_body, row)
return True

def finish(self, create_new_body=True):
""" finishes the current body by saving it into the main body or into a file (future feature) """
if create_new_body and self._current_body is not None:
for child in self._current_body:
self._body.append(child)
self._current_body = None

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is None:
self.finish(True)
self._body.append(self._last_section)

class MailMerge(object):
@@ -670,8 +683,11 @@ def merge_templates(self, replacements, separator):
continue

with MergeDocument(root, separator) as merge_doc:
create_new_body = True
for i, row in enumerate(replacements):
merge_doc.merge(self.merge_data, row, first=(i==0))
merge_doc.prepare(create_new_body=create_new_body, first=(i==0))
create_new_body = merge_doc.merge(self.merge_data, row)
merge_doc.finish(create_new_body)

def merge_pages(self, replacements):
"""