chrisfcarroll / MailMerge

Merge component for OfficeOpenXml .docx (i.e. Microsoft Word) documents
GNU General Public License v3.0
19 stars 7 forks source link

Issue #7 split mergefields #8

Closed AllTaken closed 1 year ago

AllTaken commented 3 years ago

Mergefields that are split across several instrText elements are collected and added to instrRuns.

State for pending fieldname removed, as this should be handled by the loop collecting the sequential instrText nodes.

Fixes issue #7

AllTaken commented 3 years ago

Note that this fix is based on my interpretation of the following in the documentation :

For a complex field implementation, a set of runs shall be used with each run containing, in sequence, the following elements:

  • fldChar with attribute fldCharType value begin,
  • One or more instrText elements, which, collectively, contain a complete field,
  • Optionally,
    • fldChar with attribute fldCharType value separate, which separates the field from its field result,
    • Any number of runs and paragraphs that contains the most recently updated field result, and
  • fldChar with attribute fldCharType value end.

Interpreted to mean that when there are multiple instrText elements, they must be sequential, and that these sequential elements cannot contain multiple fields (except maybe as nested fields, but that is another issue).