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

Conversation

iulica
Copy link

@iulica iulica commented Mar 8, 2022

The changes implement support for MERGE fields inside other fields, and formatting flags.

Description

Fields spanning several paragraphs are detected and proper integration with MERGEFIELDS values is implemented.
Number and text formatting and flags are implemented.
Support for date formatting is added, but not yet implemented.
A framework for easier testing of formats is also added along with tests for all changes.
Previous tests are also passed, although some tests are incorrect. For those tests a flag is implemented to be able to remove the workarounds for those tests after review.
When documents with nested fields are created, these documents need to be updated, by selecting the whole document and pressing F9. There is a flag for auto-updating all fields when opening the document. Support for setting this flag is also added (no, always, auto). Default is no, for backward compatibility.

Motivation and Context

It allows using more complex documents, that have formatting and complex fields.
Several issues are solved, mostly about using MERGEFIELDS inside other fields like IF or INCLUDEPICTURE.
#102 #88 #80 #78 #60 #52 #40

How Has This Been Tested?

All the changes have their own tests.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@iulica
Copy link
Author

iulica commented Mar 9, 2022

The rewrite code is split into 4 different classes:
MailMerge - main API, handles the reading/writing of the docx ZIP file, the parts of the document, and also getting the fields from the xml
MergeDocument - handles multi-document mail merges (separators, etc)
MergeField - one data field, handles the data formatting for one field
MergeData - factory for MergeField handles the merge of replacement data into one part (body)

iulica and others added 6 commits March 9, 2022 17:32
…ementing multiple flags (issue Bouke#40), raise warnings instead of exception on invalid field instructions
plan to release as v. 0.6.0 instead of 0.5.0, updated the documentation
Credits and link to the original repository.
Fixed the Credits topic
@iulica iulica closed this Mar 31, 2022
@iulica iulica reopened this Mar 31, 2022
iulica and others added 30 commits April 15, 2022 16:38
Removed NEXT and added SKIPIF
Added content type footnotes+xml so mail merge fields are supported
Revert "Added content type footnotes+xml so mail merge fields are supported"
Adds failed test for merge_templates footnotes
Fix for handling footnotes when merging a single documents
Refactored test_nested_fields.py
Added draft support for merge_params (update the fields instead of replacing them)
Added tests for merge fields (still incomplete)
Fixes #9 Bouke#104 Bouke#82 Bouke#70
Implemented the SimpleMergeField class and added support for more classes.
Added tests for the keep_fields parameter none,some,all
Tests for UniqueIdsManager
Refactor Mailmerge.parts to be more flexible for handling different
categories of parts
Refactor settings with the new category of parts
Refactored some tests to use the generic document extraction method
Added support for adding new XML files in the docx. (new headers/footers)
Added support for various generation of IDs in the docx
Refactored the parts so that all docx files can be handled in a generic way.
Refactored the settings using the parts.
A new method to insert dynamic images.
removed TODO item as no longer on the list
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants